码迷,mamicode.com
首页 > 编程语言 > 详细

JavaScript HashTable

时间:2016-01-11 23:51:08      阅读:233      评论:0      收藏:0      [点我收藏+]

标签:

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‘);

  

JavaScript HashTable

标签:

原文地址:http://www.cnblogs.com/shidengyun/p/5122736.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!