I've run into an interesting problem porting some of my code from C and C# to javascript. Specifically as part of it it hashes a portion of an array of 16bit numbers. The general shape is:
This is normally blazingly fast as the operations pretty much boil down to straight CPU instructions. However, the problem i'm running into in javascript is that i can't seem to inform the JITs that this is all 32bit math that i'm trying to do. So, due to things like multiplication, the hash gets larger than than fixed size that the VM uses for in place integers and eventually becomes a float, causing both rejits and generally slower performance.
What i'm looking for then is a hashing function that works over a sequence of numbers that produces a reasonably well distributed hash while operating only within 31 bits (the max int size for VMs like V8 and chakra that use tagged integral values).
So fast and lean with reasonable distribution. Does anyone have anything like that that is available for use?
Thanks!
Code:
function hash(array, start, length) {
var h = ...
// for each number in that segment
h = lots *
of <<
math ^
operations %
}
This is normally blazingly fast as the operations pretty much boil down to straight CPU instructions. However, the problem i'm running into in javascript is that i can't seem to inform the JITs that this is all 32bit math that i'm trying to do. So, due to things like multiplication, the hash gets larger than than fixed size that the VM uses for in place integers and eventually becomes a float, causing both rejits and generally slower performance.
What i'm looking for then is a hashing function that works over a sequence of numbers that produces a reasonably well distributed hash while operating only within 31 bits (the max int size for VMs like V8 and chakra that use tagged integral values).
So fast and lean with reasonable distribution. Does anyone have anything like that that is available for use?
Thanks!