Javascript Data Structure Hash Table 5
var hash = new HashTable(); hash.put("A", "a@email.com"); hash.put("B", "b@email.com"); hash.put("C", "c@email.com"); console.log(hash.get("A")); console.log(hash.get("D")); function HashTable(){ var table = []; this.put = function(key, value){ var position = loseloseHashCode(key); console.log(position + ' - '+key); table[position] = value;// ww w . j ava 2 s . c o m }; this.remove = function(key){ table[loseloseHashCode(key)] = undefined; }; this.get = function(key){ return table[loseloseHashCode(key)]; }; var loseloseHashCode = function(key){ var hash = 0; for(var i = 0; i<key.length; i++){ hash += key.charCodeAt(i); } return hash % 37; } }