var Class = {
create : function() {
return function() {
this.initialize.apply(this, arguments);
};
}
};
var Extend = function(desc, src) {
for (var property in src) {
desc[property] = src[property];
}
return desc;
};
var Base = function(){};
Base.prototype.extend = function(obj) {
return Extend.apply(this, [this, obj]);
};
var Map = Class.create();
Map.prototype = (new Base()).extend({
initialize : function() {
this.length = 0;
this.maxLength = Number.MAX_VALUE;
this.container = {};
},
put : function (objName,objValue){
try{
if(this.length >= this.maxLength)
throw new Error("[Error HashMap] : Map Datas' count overflow !");
if(objValue && objName && objName != ""){
this.container[objName] = objValue;
this.length ++ ;
}
}catch(e){
return e;
}
},
get : function(objName){
try{
if(this.container[objName])
return this.container[objName];
}catch(e){
return e;
}
},
size : function(){
return this.length;
},
remove : function(objName){
try{
if(this.container[objName]){
delete this.container[objName];
this.length -- ;
}
}catch(e){
return e;
}
}
});
var HashMap = Class.create();
HashMap.prototype = (new Map()).extend({
constructor:HashMap,
keySet : function(){
var arrKeySet = new Array();
var index = 0;
for(var strKey in this.container){
arrKeySet[index++] = strKey;
}
return arrKeySet.length == 0 ? null : arrKeySet;
},
pop : function(objName){
try{
var ov = this.container[objName];
if(ov){
delete this.container[objName];
this.length -- ;
return ov;
}
return null;
}catch(e){
return e;
}
},
isEmpty : function(){
if(this.length === 0)
return true;
else
return false;
},
runIn : function(fun){
try{
if(!fun)
throw new Error("[Error HashMap] : The paramer is null !");
for(var p in this.container){
var ov = this.container[p];
fun(ov);
}
}catch(e){
return e;
}
},
values : function() {
var arrValues = new Array();
var index = 0;
for(var strKey in this.container){
arrValues[index++] = this.container[strKey];
}
return arrValues.length == 0 ? null : arrValues;
},
contains : function(objValue){
try{
for(var p in this.container){
if(this.container[p] === objValue)
return true;
}
return false;
}catch(e){
return e;
}
},
removeAll : function(){
this.clear();
},
clear : function(){
try{
delete this.container;
this.container = {};
this.length = 0;
}catch(e){
return e;
}
},
putAll : function(map){
if(map == null)
return;
if(map.constructor != HashMap)
return;
var arrKey = map.keySet();
var arrValue = map.values();
for(var i in arrKey)
this.put(arrKey[i],arrValue[i]);
}
});
分享到:
相关推荐
用js代码实现java中hashmap 的所有功能
模拟java中的HashMap类js类对象,可以与js的Array类对象配合使用
一个用于js里面 用javascript实现的HashMap类
NULL 博文链接:https://mox-sir.iteye.com/blog/2124644
Javascript实现和操作HashMap,压缩包里面有hashmap定义和操作的例子
NULL 博文链接:https://brucexx.iteye.com/blog/491449
javaScript模拟的HashMap数据结构,可以方便的put和get。几乎和Java中HashMap类的功能一模一样。非常好用的!
前端开源库-hashmaphashmap,用于javascript的hashmap类
backbee / js-hashmap JavaScript哈希图实现##安装:bower install bb-js-hashmap --save ##特性: HashMap . length 返回HashMap对象中键/值对的数量。 HashMap . size 返回HashMap对象中键/值对的数量。 ## ...
NULL 博文链接:https://heisetoufa.iteye.com/blog/342983
JavaScript 中的 HashMap 实现。 就像在 Java 中一样,但不是。 用法 var capacity = 16 , loadFactor = 0.75 , // default value hashMap = new HashMap ( capacity , loadFactor ) ; hashMap . put ( "someKey...
主要介绍了JS hashMap实例详解的相关资料,包括删除键值、获取键值的相关知识,非常不错具有参考借鉴价值,需要的朋友一起看看吧
javascript collections (HashMap, Set, ArrayList, etc.)
适用于JavaScript的HashMap类 安装 使用 : $ npm install hashmap 使用凉亭: $ bower install hashmap 您可以从下载最新的稳定版本。 如果您喜欢冒险,可以下载,它通常是稳定的。 要运行测试: $ npm test ...
实现类似于Java中的HashMap功能,作为一个脚本中的Collection使用,可自行扩展功能。
受JDK 8启发的HashMap JavaScript类 小心 这是一个进行中的工作(嗯,更像是大多数完成的工作)。 安装 使用npm: $ npm install hashmap-jdk 使用浏览器(即将提供Bower支持): 如果您想尝试一下,可以下载,它...
主要介绍了javascript实现的HashMap类代码,实现了添加、获取、删除、查询key和value功能,需要的朋友可以参考下
该项目提供了可在Node.js和浏览器上运行的HashMap和LinkedHashMap类。 它们都是像一样的简化实现 它使用改进的算法生成哈希。 这样可确保在所有铲斗上尽可能广泛地散布。 根据规范,基本Hashmap不能保证在迭代时...
pvo是基于List这样的数据结构实现的通用DAO工具,在pvo_1.3资源文件中新增了用于客户端的pvo.js文件,用于服务端的ProcessForm类,这是一个通用的表单解析工具,是一个正真万能的表单解析工具。pvo_1.3用“HashMap...