fnv- plus (日语)
Javascript FNV-1a Hashing Algorithm上至1024位,高度优化了32位和52位的实现.
概念
FNV-1a散列算法,常被简单地称为"fnv",会分散散列 整个正位散列空间的分散度非常高 快点.
使用此模块生成 Javascript 唯一的散列/ 检查和和值 字符串或对象. 说明: FNV-1a算法甚至不适宜于 密码伪随机生成器,不应用于保护任何 任何原因都一样 它的设计为 特性没有 随机性。 。 。 .
为什么 fnv- plus (日语)? 吗?
- 这是 快点 可供节点Js使用的FNV执行 脱口而出) (中文(简体) ). 见 基准。 。 。 .
- 它是唯一能够为大于32位的密钥空间生成fnv hashes的npm模块.
fnv-plus已经测试过了 许多其他fnv的应用没有提供单位测试来证明它们的工作和表现.fnv-plus执行一个52bit版本的FNV-1a,它提供了更大的散列空间,同时仍然使用Javascript的53位整数空间.
1.3.x 新设
- 没有依附关系!
- 快速变换 优化速度.
1.2.x中新建
- 您可以轻松定义自定义种子 .
- 页:1
hash()函数现在可以将任意 Javascript 对象作为输入. - 默认位长改为 第52条
安装
$ 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'
API 密码
fnv.hash(string, bitlength)
- 使用给定比特长度( 52 为默认值) 将字符串挂起
- 返回 a
FnvHash对象
fnv.seed(string)
- 种子算法生成不同的值. 使用同样的值 不同的种子很可能会产生不同的结果。 尽可能 你的种子可以是随机的, 它可以作为随机的来源,但 不过 没有 替换密码式PRG( pseudo-random) 发电机).
- 默认种子是
chongo <Landon Curt Noll> /\>./\\
fnv.useUTF8(bool)
- UTF-8 对散列函数的认识
- 默认为
false
FnvHash.str()
返回作为 ASCii 字符串的散列值
FnvHash.hex()
以十六进制字符串返回散列值
FnvHash.dec()
以小数字符串返回散列值
快速变体
这个功能运行得更快,因为它们没有 自由管理 (见
基准 以获得更多信息。 他们总是计算1a
版本的散列并总是使用默认种子. 直接返回散列值
(无) FnvHash 对象).
fnv.fast1a32(string)
- 计算 FNV-1a 32 位散列
- 返回输入
fnv.fast1a32hex(string)
- 计算 FNV-1a 32 位散列
- 返回十六进制字符串
fnv.fast1a52(string)
- 计算 FNV-1a 52 位散列
- 返回输入
fnv.fast1a52hex(string)
- 计算 FNV-1a 52 位散列
- 返回十六进制字符串
fnv.fast1a64(string)
- 计算 FNV-1a 64 位散列
- 返回十六进制字符串
fnv.fast1a32utf(string)
- 计算 FNV-1a 32 位散列
- 处理 UTF-8 字符串
- 返回输入
fnv.fast1a32hexutf(string)
- 计算 FNV-1a 32 位散列
- 处理 UTF-8 字符串
- 返回十六进制字符串
fnv.fast1a52utf(string)
- 计算 FNV-1a 52 位散列
- 处理 UTF-8 字符串
- 返回输入
fnv.fast1a52hexutf(string)
- 计算 FNV-1a 52 位散列
- 处理 UTF-8 字符串
- 返回十六进制字符串
fnv.fast1a64utf(string)
- 计算 FNV-1a 64 位散列
- 处理 UTF-8 字符串
- 返回十六进制字符串
许可证
麻省理工学院