Last active
October 13, 2015 17:13
-
-
Save dawsbot/8d00f382e52116b94937 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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