cruxhash
TypeScript icon, indicating that this package has built-in type declarations

2.1.1 • Public • Published

CRUXHash

View on NPM License

A set of crucial hash functions for ECMAScript.

Installation

Use the npm package manager to install CRUXHash.

npm i cruxhash

Usage

CRUXHash provides a set of simple functions to create unsigned 32-bit integer hash codes for trivial ECMAScript values. See the example bellow:

import { hash, getSeed } from 'cruxhash';

console.log(hash('Smile, my dear!')); // returns 2890382619

console.log(hash(42)); // returns 1462734105

console.log(hash(42, getSeed('my seed'))); // returns 8142968

console.log(hash({ a: 10, b: 10 })); // returns 3685477545

console.log(hash([1, 2, 3])); // returns 2610324319

console.log(hash('コンニチハ, Hello world, Καλημέρα κόσμε 😀')); // returns 1898574527

Most of times, the function hash is sufficient for making the hash codes. If you need some tampering, pass a number to the seed parameter to start the hash algorithm. You can use the the getSeed function to generate some seeds from strings. Other functions are available, see the Wiki's Page for the complete API.

CRUXHash uses Murmur3 as the hashing algorithm in most of cases, the exception is when hashing 32bit integers, where it uses Thomas Wang's shift and multiplication algorithm.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

Package Sidebar

Install

npm i cruxhash

Weekly Downloads

5

Version

2.1.1

License

MIT

Unpacked Size

25.1 kB

Total Files

7

Last publish

Collaborators

  • maxroecker