[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:
derrod 2020-05-06 19:49:45 +02:00
parent efed0f07da
commit 5d91b2b59f

View 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