node package manager
Easy collaboration. Discover, share, and reuse code in your team. Create a free org ยป



A perfect minimal hash function generator

A perfect hash function for a set S is a hash function that maps distinct elements in S to a set of integers, with no collisions.

A minimal perfect hash function also yields a compact hash table, without any vacant slots.

The generator here is a port of Steve Hanov's perfect minimal hash generator.


npm install --save perfect

Usage example

var perfect = require('perfect');

var dict = { a: 'a', b: 'b', c: 'c', d: 'd' },
    tables = perfect.create(dict);

Object.keys(dict).forEach(function(key) {
  console.log('key: ' + key + ' value: ' +  perfect.lookup( tables[0], tables[1], key));