javascript实现了一组映射

javascript实现了一组映射
几天前,这个项目想用地图把同样的东西组装起来,简单地把物体放在一起很短的时间。

我们不应该嘲笑我。

代码
var map =函数(){()
基于变************** ************ / /
Var HashMap = { };
var键= };
VaR值= { };
VaR任务= { };
var大小= 0;
var索引{ };

var =函数(键,值){
无功entrykey =关键;
Var entryValue = value;
this.getkey =函数(){
Return entryKey;
};
this.getvalue =函数(){
返回entryvalue;
};
};
/ ************基本方法按字母排序的************** /
this.clear =功能(关键){
HashMap { } =定义的关键;
var =索引{键};
entrys.splice(I,1);
vals.splice(I,1);
Keys.splice(I,1);
大小—;
};

this.entryset =函数(){
返回任务;
};

this.get =功能(关键){
返回HashMap {key};
};

this.isempty =函数(){
如果(HashMap)返回true;
返回false;
};

this.keyset =函数(){
返回键;
};

this.put =功能(键,值){
如果(!this.get(关键)){
Entrys.push(新条目(键,值));
Keys.push(重点);
Vals.push(值);
索引{键} =大小;
大小+;
{人}
var =索引{键};
任务{我} =新条目(键,值);
瓦尔斯{我} =价值;
}
HashMap {key} =价值;
};

this.size =函数(){
返回的大小;
};

this.values =函数(){
返回值;
};
};
/ ************扩展方法************** /
map.prototype = { {
ContainsKey:功能(关键){
如果(this.get(关键))返回true;
返回false;
},
PutAll:功能(套){
对于(set中的var){
如果(设置{ }){
This.put(E,E组{ });
}
}
},
删除:函数(键){
var v = this.get(关键);
this.clear(关键);
返回v;
}
};
新地图();
H.put(A,10);
H.put(B,11);
H.put(C,3);
H.put(D'5);
Console.info(h.size());
h.clear(A);
Console.info(h.containskey(A));
Console.info(h.containskey(B));
Console.info(h.size());

console.log(h.entryset());
console.log(h.keyset());
console.log(h.values());

对于(VAR我h.entryset()){
var obj = h.entryset(){ };
console.log(obj.getkey()+:+ obj.getvalue()));
}
以上是本文的全部内容,希望大家能喜欢。

tag:映射实现了电脑软件Javascript

相关内容