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

jump-gouache

v2.1.1

Published

Port of Guava jump consistent hash function

Downloads

1,298

Readme

Jump-Gouache

npm version Build Status Quality Gate Status

Description

This is a port of Guava consistent hash function in TypeScript alias the jump guava hash algorithm, in short jump-gouache.

Jump-Gouache was created as there was no fully compatible library of this algorithm available for nodejs runtime.

This aims at computing the same bucket index from a 32 bit or 64 bit integer and buckets as in Guava, thus using the same Linear Congruential Generator as in Guava with the same constants.

This library produces the same outputs as many other libraries that implement the jump consistent hash algorithm. For instance :

This library is made with compatibility in mind, all used algorithms are standard so it should work nicely in environments where there are lots of different tech stacks.

Basic usage with numeric values

Install the dependency

yarn add jump-gouache

Import the function and start hashing. The basic consistentHash function accepts number and bigint values.

import { jump } from 'jump-gouache';
 
const bucketIndexNumber = jump(45645664, 100);
const bucketIndexBigInt = jump(BigInt('0xdeadbeef'), 100);

Hashing with strings

It is also possible to use a string as input, the hashing of the string into an integer is made with fnv-plus. FNV-1a algorithm is very fast and designed for great uniform distribution (not for security).

import { fnvConsistentHash } from 'jump-gouache';
    
const hash64Result = fnvConsistentHash(
    'Text that will be hashed with FNV-1a into a 64 bit integer', 
     100);
const bucket64 = hash64Result.bucket;
const hash64 = hash64Result.hash;

const hash32Result = fnvConsistentHash(
    'Text that will be hashed with FNV-1a into a 32 bit integer', 
    100, 
    'FNV1A_32');
const bucket32 = hash32Result.bucket;
const hash32 = hash32Result.hash;

The 32 bit mode is available, it is way faster than the 64 bit one. It all depends if you want to use a wider range of hashed values from strings. Wider range means more unique hashed integer values and better distribution from jump consistent hash at the expense of more computation due to more 64 bit operations.

Another popular choice is to use MurmurHash3 thanks to murmurhash3js. Although the algorithm is great, there is no available implementation for 64 bit, thus it is not possible to use the widest hash target range of the jump algorithm, some will consider it suboptimal, others will see it as more compatible with their actual hash functions.

import { murmurConsistentHash } from 'jump-gouache';

const hash32Result = murmurConsistentHash(
    'Text that will be hashed with MurmurHash3 into a 32 bit integer', 
    100);
const bucket32 = hash32Result.bucket;
const hash32 = hash32Result.hash;

Compatibility & dependencies

Jump-gouache is compatible node 10 & node 12+. It does not require using esnext as targeted runtime.

Dependencies that are used:

  • Long: necessary for using 64 bit integer values and bitwise operations on such integers
  • Bignumber.js: necessary for using 64 bit float values
  • FNV-plus: used to hash strings into integers (32 bit or 64 bit)
  • Murmurhash3js: used to hash strings into integers (32 bit only)