Warp/src/Util/Identifier.luau

25 lines
504 B
Text
Raw Normal View History

--!optimize 2
--!native
--@EternityDev
local BITS: number = 8
local MAX_VALUE: number = bit32.lshift(1, BITS) - 1
local cache: { [string]: number } = {}
local hash: number = game.PlaceVersion + 5381
return function(name: string): number
local cached = cache[name]
if cached then
return cached
end
local b: number = hash
for i = 1, #name do
2026-02-13 12:31:40 +00:00
b = bit32.bxor(bit32.lshift(b, 5) + b, string.byte(name, i))
end
local reduced = bit32.band(b, MAX_VALUE)
cache[name] = reduced
return reduced
end