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

node-hashes

v0.1.0

Published

some of the more common uses of hash functions

Downloads

78

Readme

node-hashes

node version travis build appveyor build test coverage npm version npm downloads Code Climate

Some of the more common uses of hash functions.

Hash Function Algorithms

RS Hash Function

A simple hash function from Robert Sedgwicks Algorithms in C book.

JS Hash Function

A bitwise hash function written by Justin Sobel.

PJW Hash Functionh

This hash algorithm is based on work by Peter J. Weinberger of AT&T Bell Labs. The book Compilers (Principles, Techniques and Tools) by Aho, Sethi and Ulman, recommends the use of hash functions that employ the hashing methodology found in this particular algorithm.

ELF Hash Function

Similar to the PJW Hash function, but tweaked for 32-bit processors. Its the hash function widely used on most UNIX systems.

BKDR Hash Function

This hash function comes from Brian Kernighan and Dennis Ritchie's book "The C Programming Language". It is a simple hash function using a strange set of possible seeds which all constitute a pattern of 31....31...31 etc, it seems to be very similar to the DJB hash function.

SDBM Hash Function

This is the algorithm of choice which is used in the open source SDBM project. The hash function seems to have a good over-all distribution for many different data sets. It seems to work well in situations where there is a high variance in the MSBs of the elements in a data set.

DJB Hash Function

An algorithm produced by Professor Daniel J. Bernstein and shown first to the world on the usenet newsgroup comp.lang.c. It is one of the most efficient hash functions ever published.

DEK Hash Function

An algorithm proposed by Donald E. Knuth in The Art Of Computer Programming Volume 3, under the topic of sorting and search chapter 6.4.

AP Hash Function

An algorithm produced by Arash Partow.

BP Hash Function

That code converts a (7-bit) ASCII string of at most (4 or 9) characters into a unique (32- or 64-)bit integer, depending on the platform. If more characters are given, the first n-(5 or 10) characters are ignored, the low (4 or 1) bits of the next character are used, and the last (4 or 9) characters are used in full. The code does not use the length of the string, so leading null characters are ignored.

FNV Hash Function

The basis of the FNV hash algorithm was taken from an idea sent as reviewer comments to the IEEE POSIX P1003.2 committee by Glenn Fowler and Phong Vo back in 1991.

MurmurHash3

MurmurHash is a non-cryptographic hash function suitable for general hash-based lookup.It was created by Austin Appleby in 2008.It comes in 3 variants - a 32-bit version that targets low latency for hash table use and two 128-bit versions for generating unique identifiers for large blocks of data, one each for x86 and x64 platforms.

Install

$npm install node-hashes --save

Usage

var hashes = require('node-hashes');
var ret = hashes.RSHash('foo');
var hashes = require('node-hashes');
var seed = 32;
var ret = hashes.MurmurHash3_x86_128('foo', seed);
for (var i=0; i<ret.length; i++) {
    console.info(ret[i]);
}

Benchmarks

  • RsHash(key) x 2,146,582 ops/sec ±0.36% (93 runs sampled)
  • JSHash(key) x 2,182,381 ops/sec ±0.35% (92 runs sampled)
  • PJWHash(key) x 1,926,879 ops/sec ±0.30% (93 runs sampled)
  • ELFHash(key) x 1,891,659 ops/sec ±0.38% (90 runs sampled)
  • BKDRHash(key) x 1,857,905 ops/sec ±0.64% (91 runs sampled)
  • ELFHash(key) x 1,894,290 ops/sec ±0.34% (89 runs sampled)
  • SDBMHash(key) x 1,912,925 ops/sec ±0.54% (90 runs sampled)
  • DJBHash(key) x 2,030,426 ops/sec ±0.23% (93 runs sampled)
  • DEKHash(key) x 1,913,679 ops/sec ±0.52% (92 runs sampled)
  • BPHash(key) x 1,970,864 ops/sec ±0.43% (91 runs sampled)
  • FNVHash(key) x 1,784,257 ops/sec ±0.51% (90 runs sampled)
  • APHash(key) x 1,780,209 ops/sec ±0.39% (92 runs sampled)
  • MurmurHash3_x86_32(key, 42) x 2,491,832 ops/sec ±0.42% (91 runs sampled)
  • MurmurHash3_x86_128(key, 42) x 580,621 ops/sec ±0.51% (91 runs sampled)
  • Fastest is MurmurHash3_x86_32(key, 42)

Functions

  • RSHash(key);
  • JSHash(key);
  • PJWHash(key);
  • ELFHash(key);
  • BKDRHash(key);
  • SDBMHash(key);
  • DEKHash(key);
  • BPHash(key);
  • FNVHash(key);
  • APHash(key);
  • MurmurHash3_x86_32(key [,seed]);
  • MurmurHash3_x86_128(key [,seed]);

People

License

GitHub license