flier / pyfasthash

Python Non-cryptographic Hash Library
Apache License 2.0
281 stars 52 forks source link

murmur3 compatibility with other libraries #71

Open dhulchuk opened 6 months ago

dhulchuk commented 6 months ago

In case someone is locked to this not maintained package due to different behaviour of murmur3_32 on strings. You can get the same hash by adding zero byte after every symbol. Example for mmh3 library:

import pyhash
import mmh3

zero_spaced_string = ''.join(x + '\x00' for x in original_string)
assert mmh3.hash(zero_spaced_string, signed=False) == pyhash.murmur3_32()(original_string)

This may not be general solution, but it works for my setup.