npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

consistent-fnvxor32

v0.3.0

Published

Consistent hashing using FNV32 and Xorshift 32

Downloads

24

Readme

consistent-fnvxor32

Consistent hashing using FNV32-a1 and Xorshift 32

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

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

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 hash fnv32-a1

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