https://github.com/ceejbot/jumphash
Really remarkably trivial node bindings for Google's jump consistent hash.
https://github.com/ceejbot/jumphash
Last synced: about 1 year ago
JSON representation
Really remarkably trivial node bindings for Google's jump consistent hash.
- Host: GitHub
- URL: https://github.com/ceejbot/jumphash
- Owner: ceejbot
- License: isc
- Created: 2015-03-16T00:18:03.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2017-07-25T04:41:07.000Z (almost 9 years ago)
- Last Synced: 2025-06-20T13:33:48.372Z (about 1 year ago)
- Language: JavaScript
- Size: 24.4 KB
- Stars: 4
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @ceejbot/jumphash
Really remarkably trivial node bindings for Google's [jump consistent hash](http://arxiv.org/pdf/1406.2294v1.pdf).
[](http://travis-ci.org/ceejbot/jumphash) [](https://www.npmjs.com/package/@ceejbot/jumphash)
Tested on nodes 4, 6, and 7. Is probably just fine on node 0.10 too.
```
npm install --save @ceejbot/jumphash
```
## Usage
This module provides one function: `jumphash(key, bucketCount)`. `key` must be a non-negative integer or a buffer. `bucketCount` must be a positive integer (0 is an invalid bucket count).
The return value is a integer in the range `[0, bucketCount)` that you can use as you wish. The paper linked above describes the intended data storage use.
```javascript
var jumphash = require('@ceejbot/jumphash')
assert = require('assert'),
crypto = require('crypto');
var location = jumphash(23102, 16);
assert(location >= 0);
assert(location < 16);
var buffer = crypto
.createHash('md5')
.update('my-string-key-for-some-resource')
.digest();
var location2 = jumphash(buffer, 16);
```
Only the first 64 bits of the buffer are considered, with the most significant bit first.
## License
ISC