# consistent-fnvxor32

> Consistent hashing using FNV32 and Xorshift 32

Latest version **0.3.0** (published 2018-09-25) · BSD-2-Clause license · 0 weekly downloads

## Install

```sh
npm install consistent-fnvxor32
pnpm add consistent-fnvxor32
yarn add consistent-fnvxor32
bun add consistent-fnvxor32
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.0 |
| Published | 2018-09-25 |
| First published | 2018-05-12 |
| Weekly downloads | 0 |
| License | BSD-2-Clause |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 135.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Shane Holloway |
| Maintainers | shanewholloway |
| Keywords | hashing, hash ring, consistent hash, consistent hash ring, sharding |

## Links

- npm: https://www.npmjs.com/package/consistent-fnvxor32
- Repository: https://github.com/shanewholloway/js-consistent-fnvxor32
- Homepage: https://github.com/shanewholloway/js-consistent-fnvxor32#readme
- Issues: https://github.com/shanewholloway/js-consistent-fnvxor32/issues
- npm.io page: https://npm.io/package/consistent-fnvxor32

## Alternatives

- [@gemini-wallet/core](https://npm.io/package/@gemini-wallet/core.md) — 515.6K weekly downloads
- [utility](https://npm.io/package/utility.md) — 416.6K weekly downloads
- [@primno/dpapi](https://npm.io/package/@primno/dpapi.md) — 7.2K weekly downloads
- [pi-readseek](https://npm.io/package/pi-readseek.md) — 3.7K weekly downloads
- [@emilia-protocol/verify](https://npm.io/package/@emilia-protocol/verify.md) — 1.1K weekly downloads

## Recent versions

- 0.3.0 (latest) — 2018-09-25
- 0.2.0 — 2018-09-24
- 0.1.1 — 2018-05-12
- 0.1.0 — 2018-05-12

## README

# consistent-fnvxor32

Consistent hashing using [FNV32-a1][FNV32] and [Xorshift 32][XOR32]

Keys distribution across nodes should approach a uniform statstical distribution.

The majority of key mappings should remain stable and unchanged when nodes are
added or removed.  When you add or remove `k` of `n` nodes, the mapping for any
given key should remain the same with probability `1 - k/n`.

The resulting mapping should be deterministic.


### Single target example

```javascript
import fnvxor32 from 'consistent-fnvxor32'

const nodes3 = ['First-node', 'Second-node', 'Third-node']
fnvxor32('/data/abc345', nodes3) // => Third-node
fnvxor32('/data/qrst', nodes3)   // => Second-node
fnvxor32('/data/xyz123', nodes3) // => Third-node

const nodes5 = nodes5.concat(['Fourth-node', 'Fifth-node'])
fnvxor32('/data/abc345', nodes5) // => Fifth-node
fnvxor32('/data/qrst', nodes5)   // => Fourth-node
fnvxor32('/data/xyz123', nodes5) // => Third-node

```

### Triple target example

```javascript
import {create_fnvxor32, select_top_n} from 'consistent-fnvxor32'

const ch3 = create_fnvxor32({selector: select_top_n(3)})

const nodes5 = ['First-node', 'Second-node', 'Third-node', 'Fourth-node', 'Fifth-node']

ch3('/data/abc345', nodes5) // => [ 'Fifth-node', 'Third-node', 'Second-node' ]
ch3('/data/qrst', nodes5)   // => [ 'Fourth-node', 'Second-node', 'Third-node' ]
ch3('/data/xyz123', nodes5) // => [ 'Third-node', 'Second-node', 'First-node' ]

const nodes7 = nodes5.concat(['Sixth-node', 'Seventh-node'])
ch3('/data/abc345', nodes7) // => [ 'Fifth-node', 'Sixth-node', 'Third-node' ]
ch3('/data/qrst', nodes7)   // => [ 'Fourth-node', 'Second-node', 'Sixth-node' ]
ch3('/data/xyz123', nodes7) // => [ 'Third-node', 'Second-node', 'First-node' ]

```


### References

- [Fowler–Noll–Vo][FNV32] hash `fnv32-a1`

- [XOR Shift 32][XOR32] from Marsaglia, George (July 2003). "Xorshift RNGs". Journal of Statistical Software. 8 (14). doi:10.18637/jss.v008.i14.

[FNV32]: https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function#FNV-1a_hash
[XOR32]: https://en.wikipedia.org/wiki/Xorshift

---
_Source: https://npm.io/package/consistent-fnvxor32 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
