function HashTable() { var loseHashCode = function(key) { var hash = 0; for (var i = 0; i < key.length; i++) { hash += key.charCodeAt(i) } return hash % 37 } var table = []; this.push = function(key, value) { var position = loseHashCode(key); console.log(position + ‘-‘ + key); table[position] = value } this.get = function(key) { return table[loseHashCode (key)] } this.remove = function(key) { table[loseHashCode (key)] = undefined } } var hash = new HashTable(); hash.push(‘shidengyun‘, ‘85‘); hash.push(‘zhujing‘, 86); hash.get(‘zhujing‘); hash.remove(‘zhujing‘);
时间: 2024-10-09 20:17:50