Open yhahn opened 9 years ago
I'll take look, sorry I noticed this issue just now.
I have a same issue. Please fix this as soon as possible.
P.S.: нere is my example if you need.
I've been using this module for a while now. At first I was using it with very different strings so I didn't noticed this bug. With similar strings is giving the same output! Since 52 bits is the default you get lots of collisions. Any plans on fixing this? Otherwise it should be on the docs.
Any updates on this @tjwebb ?
Yep, bitwise operators only work with 32-bit integers in JS. So this function will not work if implemented in that way. I fixed 52bit hash in #9 so it returns 52bit JS integer and computes hash according to FNV specs.
But it is important to remember what any bitwise operation will convert this hash to 32bit. So this version must be used when number is needed as is.
Another interesting fact - 52bit version is fastest one.
I just stumbled upon this while fixing a bug :D Can you publish the fixed version on npm? :)
I picked up this module to make use of the 52-bit fnv1a hashes. After some use, however, I noticed that it was generating a lot of collisions -- many more than the 32-bit fnv1a hash that we'd been using before.
To demonstrate I've put a gist together -- it hashes 1 million random text strings -- 32 and 64 bit fnv1a behave about as expected but the 52 bit hash is :flushed:
A quick glance at the code makes me a little curious about this comment https://github.com/tjwebb/fnv-plus/blob/master/index.js#L124-L128 -- afaik bitwise operators only work with 32-bit integers in JS. Is this not true?