FNV-1a 散列算法通常被简单地称为 FNV,它在 n 位散列空间中散布散列,具有很好的分散性,而且速度非常快。

使用此模块为 JavaScript 字符串或对象生成唯一的散列/校验和值。
注:FNV-1a 算法甚至不适合作为密码伪随机生成器,也不应该被用来保护任何事物的安全。它的确是唯一的,但不是随机的。
$ npm install fnv-plus --save
var fnv = require('fnv-plus'),
astring = 'hello world',
ahash52 = fnv.hash(astring), // 52-bit hash by default
ahash64 = fnv.hash(astring, 64); // 64-bit hash specified
console.log(ahash52.hex() == 'a65e7023cd59e'); //true
console.log(ahash52.str() == 'stglysbf6m'); //true
console.log(ahash52.dec() == '2926792616498590'); //true
console.log(ahash64.hex() == '779a65e7023cd2e7'); //true
console.log(ahash64.str() == '1th7cxzlyc0dj'); //true
console.log(ahash64.dec() == '8618312879776256743'); //true
// fast variants
console.log(fnv.fast1a32hex(astring) == 'd58b3fa7'); //true
console.log(fnv.fast1a52hex(astring) == 'a65e7023cd59e'); //true
fnv.seed('foobar testseed');
console.log(fnv.hash(astring, 64).hex() == ahash64.hex()); // false
// ^^ because the default seed is not 'foobar testseed'
以ascii字符串的形式返回哈希值。
以十六进制字符串的形式返回哈希值。
以十进制字符串的形式返回哈希值。
这个函数运行得更快,因为它们没有 LIB-间接费用,参见 Benchmarks 获取更多信息。他们总是计算 1a 版本的散列,并且总是使用默认的种子。直接返回哈希值(不返回 FnvHash 对象)。

