shashi
Version:
Shashi, a simple module to generate, using pseudo-randomness, a universal family/set of hash functions, which produce integer values within the selected range (a prime number)..
37 lines (35 loc) • 1.03 kB
JavaScript
/*
* Shashi re-fill seed sequence example,
*/
var log = console.log
, Shashi = require( '../' )
// items to hash
, i = 7
// how many random hash function to generate
, h = 2
// a prime to define range for seed sequence values (range = prime - 1)
, p = 104729
, result = Shashi( h, i, p )
, ufn = result[ 0 ]
, seed = result[ 1 ]
// use a sequence for input
, input = new Buffer( [ 0, 0, 0, 0, 12, 12, 12 ] )
// get 2 hash functions, reading only 1 byte at the time from input buffer
, v0 = ufn( 0, input, 1 )
, v1 = ufn( 1, input, 1 )
;
log();
log( '- %d hash functions generated with data produced by Math.random()', h );
log();
log( '- input buffer:', input );
log();
log( '- seed sequence result:', seed.result );
log();
log( '- hash results:', v0, v1 );
log();
log( '- re-fill seed sequence with Math.random()' );
log();
log( '- seed sequence result:', seed.fill().result );
log();
log( '- hash results:', ufn( 0, input, 1 ), ufn( 1, input, 1 ) );
log();