05年h
稳定的32位字符串散列(FNV-1a)与bucket helper。零依赖关系。
相同的输入总是在每个平台上产生相同的无符号32位整数 每个节点版本-适合稳定分片,缓存键和可复制 (播种)排序。
const hash = require('05h');
hash('hello'); // 1335831723
hash('hello'); // 1335831723 (always the same)
hash('hello', 100); // 23 (in [0, 100))
hash.bucket('id', 8); // 0..7 (shard index)
API
hash(value, modulo?)
| 论点 | 类型 | 描述 |
|---|---|---|
value | string | 输入。非字符串被强制使用 String(). |
modulo | number? | 当给定时,结果被简化为 [0, modulo). 无效模将被忽略。 |
返回无符号32位 number.
hash.bucket(value, buckets)
方便的包装器返回一个稳定的索引 [0, buckets).
笔记
不是加密散列-不要出于安全目的使用它。
许可证
麻省理工学院