bling-hashes
v2.0.0
Published
String hash algorithms.
Maintainers
Readme
Bling Hashes
String hash algorithms for node.js.
Installation
$ npm install --save bling-hashesIntroduce
There are 8 algorithms so far.
- BKDRHash
- APHash
- DJBHash
- JSHash
- RSHash
- SDBMHash
- PJWHash
- ELFHash
- CityHash
- CityHash32: returns a 32-bit hash.
- CityHash64: and similar return a 64-bit hash.
- CityHash128: and similar return a 128-bit hash.
The benchmark, performance and implementation can be referenced here (各种字符串Hash函数比较).
Usage
First you should require this package.
var bling = require("bling-hashes");And then you can pass any string to functions (the same name as algorithms, in lowercase).
Eg.
var hash1 = bling.bkdr("Hello world!"); ///< 501511565
var hash2 = bling.city32("玉扣"); ///< 887335438Return Values
- From
BKDRtoELF, the functions return aNumbervalue; city32returns aNumbervalue too;city64returns aLongvalue which may refer here;city128returns aCity128Valuevalue which has properties below:.toString(): The string value of the 128-bit number;.toLongArray(): An array that includes two 64-bitLongvalue;.toBuffers(): An array that includes twoBuffers..toBigNumber(): ABigNumbervalue which may refer here;
Contribution
Thanks to BYVoid. The C++ implementation code was copied from his blog.
You're welcome to make pull requests.
「雖然我覺得不怎麼可能有人會關注我」
