<script language="javascript">
function HashMap(){
/**Map大小**/
var size=0;
/**对象**/
var entry=new Object();
/**Map的存put方法**/
this.put=function(key,value){
if(!this.containsKey(key)){
size++;
entry[key]=value;
}
}
/**Map取get方法**/
this.get=function(key){
return this.containsKey(key) ? entry[key] : null;
}
/**Map删除remove方法**/
this.remove=function(key){
if(this.containsKey(key) && ( delete entry[key] )){
size--;
}
}
/**是否包含Key**/
this.containsKey= function (key){
return (key in entry);
}
/**是否包含Value**/
this.containsValue=function(value){
for(var prop in entry)
{
if(entry[prop]==value){
return true;
}
}
return false;
}
/**所有的Value**/
this.values=function(){
var values=new Array();
for(var prop in entry)
{
values.push(entry[prop]);
}
return values;
}
/**所有的 Key**/
this.keys=function(){
var keys=new Array();
for(var prop in entry)
{
keys.push(prop);
}
return keys;
}
/**Map size**/
this.size=function(){
return size;
}
/**清空Map**/
this.clear=function(){
size=0;
entry=new Object();
}
}
//创建HashMap对象
var hashMap=new HashMap();
hashMap.put("A","1");
hashMap.put("B","2");
hashMap.put("A","5");
hashMap.put("C","3");
hashMap.put("A","4");
alert(hashMap.size());
</script>
design a HashMap for js
原创mb5fb94c9d4a0ba 博主文章分类:java advanced ©著作权
文章标签 javascript get方法 文章分类 Html/CSS 前端开发
-
HashMap源码剖析
本文主要比较了jdk1.7和1.8中HashMap的put逻辑
HashMap 源码 -
706. Design HashMap刷题笔记
代码可以运行,但每个样例要300ms
leetcode python 链表 -
js版HashMap
习惯使用java的HashMap,js封装数据的时候也想用map集合,就找了一个封装
hashmap javascript java js python -
no open design no open design vivado
Vivado提供了两种运行模式:Project Mode 和Non-Project Mode,开发人员可以自行选择一种来进行开发。 &n
no open design Project mode Non-Project mode 工程模式和非工程模式 源文件