mirror of
https://github.com/derrod/legendary.git
synced 2024-12-22 17:55:27 +00:00
[utils] Add FRollingHash implementation
Seems to be a variation on CRC-64-ECMA. This python version is of course very slow. That should not be a big issue however, since it is only required for serialising rather small save game data.
This commit is contained in:
parent
efed0f07da
commit
5d91b2b59f
25
legendary/utils/rolling_hash.py
Normal file
25
legendary/utils/rolling_hash.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
# this is the rolling hash Epic uses, it appears to be a variation on CRC-64-ECMA
|
||||
|
||||
hash_poly = 0xC96C5795D7870F42
|
||||
hash_table = []
|
||||
|
||||
|
||||
def _init():
|
||||
for i in range(256):
|
||||
for _ in range(8):
|
||||
if i & 1:
|
||||
i >>= 1
|
||||
i ^= hash_poly
|
||||
else:
|
||||
i >>= 1
|
||||
hash_table.append(i)
|
||||
|
||||
|
||||
def get_hash(data):
|
||||
if not hash_table:
|
||||
_init()
|
||||
|
||||
h = 0
|
||||
for i in range(len(data)):
|
||||
h = ((h << 1 | h >> 63) ^ hash_table[c.data[i]]) & 0xffffffffffffffff
|
||||
return h
|
Loading…
Reference in a new issue