Skip to content

Instantly share code, notes, and snippets.

@gvinter
Created July 13, 2011 15:04
Show Gist options
  • Save gvinter/1080478 to your computer and use it in GitHub Desktop.
Save gvinter/1080478 to your computer and use it in GitHub Desktop.
Configurable hash functions
function max(a, b) {
this.a = a;
this.b = b;
if (a > b) {
return a;
} else {
return b;
}
}
console.log(max(100,1000));
function simple_hash(key,table_size) {
var hash = 0;
var max_var = new Number();
var max_var = max(100,1000);
for (var i = 0; i < key.length; i++) {
hash = (hash * 31) + key.charCodeAt(i);
}
return Math.abs(hash) % table_size;
}
console.log(simple_hash("test",max_var));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment