mirror of
https://github.com/imezx/Warp.git
synced 2026-03-18 00:44:16 +00:00
rewrite(phase4): lets do 16 bits instead
This commit is contained in:
parent
cd76d58c4d
commit
83c8698b9f
1 changed files with 4 additions and 4 deletions
|
|
@ -18,20 +18,20 @@ return function(name: string): number
|
||||||
return cached
|
return cached
|
||||||
end
|
end
|
||||||
|
|
||||||
local h: number = 2166136261
|
local h = 2166136261 + game.PlaceVersion
|
||||||
for i = 1, #name do
|
for i = 1, #name do
|
||||||
h = bit32.bxor(h, string.byte(name, i))
|
h = bit32.bxor(h, string.byte(name, i))
|
||||||
h = bit32.band(h * 16777619, 0xFFFFFFFF)
|
h = bit32.band(h * 16777619, 0xFFFFFFFF)
|
||||||
end
|
end
|
||||||
|
|
||||||
local id = h % 254 + 2
|
local id = h % 65534 + 2
|
||||||
|
|
||||||
local existing = used[id]
|
local existing = used[id]
|
||||||
if existing and existing ~= name then
|
if existing and existing ~= name then
|
||||||
warn(`[Warp] Hash collision: "{name}" & "{existing}" both map to ID {id}`)
|
error(`[Warp] Hash collision: "{name}" & "{existing}" both map to ID {id}. Rename one.`)
|
||||||
end
|
end
|
||||||
|
|
||||||
cache[name] = id
|
cache[name] = id
|
||||||
used[id] = name
|
used[id] = name
|
||||||
return id
|
return id
|
||||||
end
|
end
|
||||||
Loading…
Reference in a new issue