日期:2014-05-16  浏览次数:20326 次

javascript实现简单的hashmap
?
hashmap是最常用的数据结构之一,但javascript并没有支持,在网上找了下,发现了个,实现非常简单
?
//hashMap对象定义
var hashMap = {??
?????put : function(key,value){this[key] = value},??
???? get : function(key){return this[key]},??
???? contains : function(key){return this.get(key) == null?false:true},??
???? remove : function(key){delete this[key]}??
};
//方法说明
?//在hashMap对象中添加值
?hashMap.put("language","JavaScript");
//在hashMap对象中获取值,返回数据:“JavaScript”
?hashMap.get("language");
//判断hashMap对象中是否有指定变量
?hashMap.contains("language");//返回True
?hashMap.contains("type");//返回false
//移除已存在的变量
?hashMap.remove("language");

原链接文:http://hi.baidu.com/terry05/blog/item/801f0cb3115ef0a0d9335aab.html