The FNV-1a hash algorithm, often simply called "fnv", disperses hashes throughout the n-bit hash space with very good dispersion and is very fast.
- I call this module
fnv-plusbecause it is the only npm module that is capable of generating fnv hashes for keyspaces larger than 32 bits.
fnv-plusis well-tested. Many other fnv implementations offer no unit tests to prove they work and are performant.
fnv-plusimplements a 52bit version of FNV-1a which provides a larger hash space while still making use of Javasript's 53-bit integer space.
New in 1.2.x
- You can easily define custom seeds.
- changed default bitlength to 52
$ npm install fnv-plus --save
var fnv = require('fnv-plus'), astring = 'hello world', ahash32 = fnv.hash(astring), // 32-bit hash by default ahash64 = fnv.hash(astring, 64); // 64-bit hash specified assert.equal(ahash32.hex(), '0xb23eba32'); assert.equal(ahash32.str(), '1dgfu42'); assert.equal(ahash32.dec(), '2990455346'); assert.equal(ahash64.hex(), '0xa8dd8fbdc2b13ffc'); assert.equal(ahash64.str(), '2kg3e4gji835o'); assert.equal(ahash64.dec(), '12168039813402935292'); fnv.seed('foobar testseed'); assert.notEqual(fnv.hash(astring), ahash64); // ^^ because the default seed is not 'foobar testseed'
- Hash a string using the given bit length (52 is default)
- returns a
- Seed the algorithm to produce different values. Hashing the same value with different seeds will very likely result in different results. To the extent your seed can be random, it can serve as a source of randomness, but nonetheless is not a replacement for a crypgographic PRG (pseudo-random generator).
- default seed is
chongo <Landon Curt Noll> /\>./\\
Returns the hashed value as an ascii string
Returns the hashed value as a hexadecimal string
Returns the hashed value as a decimal string