Skip to content

Instantly share code, notes, and snippets.

@dawsbot
Last active October 13, 2015 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dawsbot/8d00f382e52116b94937 to your computer and use it in GitHub Desktop.
Save dawsbot/8d00f382e52116b94937 to your computer and use it in GitHub Desktop.
//Testing to come soon
var md5 = require('md5');
function table() {
//Implement the hash table with one array
this.arr = [];
//Use a hack of md5 to implement a number 0 <= encoded <= 9
this.encode = function (toEncode){
var encoded = md5(toEncode);
var pretty = parseInt(encoded, 16);
var lengthLimited = pretty % 10;
return lengthLimited;
};
this.set = function(key, value) {
var encoded = Number(this.encode(key));
this.arr[encoded] = [key, value];
};
this.get = function(key) {
var encoded = Number(this.encode(key));
return this.arr[encoded];
};
this.delete = function(key) {
var encoded = Number(this.encode(key));
this.arr[encoded] = undefined;
};
}
var table = new table();
table.set('hello', 99);
table.set('blah', -9);
console.log(table.get('hello'));
table.delete('hello');
console.log(table.arr);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment