Skip to content

liushoukai/node-hashes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Some of the more common uses of hash functions.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •