murmur
v0.0.2
Published
Murmur3 Hashing functions for NodeJS
Downloads
252
Readme
Murmur3
A NodeJS module for sub-millisecond, non-cryptographic hashes using the Murmur3 algorithm.
Note: As of v0.0.1, only the 128 bit hash is supported.
Bonus
Javascript does not contain 64 bit operations....
Instead, the standard complies to a 64 bit floating point representation that gives 58 bits of precision in integers.
To overcome this, I had to fill in these gaps. As such, I have allowed these operations to be accessed from the murmur
object.
The functions include:
add64(a, b)
:: Additionmult64(a, b)
:: Multiplicationshiftr(a, bits)
:: Shift rightshiftl(a, bits)
:: Shift leftrotl(a, bits)
:: Rotate leftwhere (a) or (b) are a 64 bit integer of format [nHigh, nLow]
Hash Usage
var murmur = require('murmur3');
// NOTE: currently only 128 bit length is implemented
// remember, array of 4 "32 bit unsigned integers"
var hash = murmur.hash128('string of text or data');
// or with a seed (limited to 32 bit address space)
var seeded = murmur.hash128('string of text or data', 0xFFFFFFFF)
// returns 16 character hex representation as a string
var string_hex = murmur.hex(hash);
Testing
Install mocha
and should
using
npm install --dev
Note: npm 1.2.18
contains a bug that tries to install the development version of all devDependencies. Omit the --dev
option and it should work correctly.
Once everything is installed:
make test