You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
1.9 KiB
72 lines
1.9 KiB
7 years ago
|
|
||
8 years ago
|
!(function () {
|
||
|
BI.LinkHashMap = function () {
|
||
|
this.array = [];
|
||
|
this.map = {};
|
||
|
};
|
||
|
BI.LinkHashMap.prototype = {
|
||
|
constructor: BI.LinkHashMap,
|
||
|
has: function (key) {
|
||
|
if (key in this.map) {
|
||
|
return true;
|
||
|
}
|
||
|
return false;
|
||
|
},
|
||
|
|
||
|
add: function (key, value) {
|
||
7 years ago
|
if (typeof key === "undefined") {
|
||
8 years ago
|
return;
|
||
|
}
|
||
|
if (key in this.map) {
|
||
|
this.map[key] = value;
|
||
|
} else {
|
||
|
this.array.push(key);
|
||
|
this.map[key] = value;
|
||
|
}
|
||
|
},
|
||
|
|
||
|
remove: function (key) {
|
||
|
if (key in this.map) {
|
||
|
delete this.map[key];
|
||
|
for (var i = 0; i < this.array.length; i++) {
|
||
|
if (this.array[i] == key) {
|
||
|
this.array.splice(i, 1);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
|
||
|
size: function () {
|
||
|
return this.array.length;
|
||
|
},
|
||
|
|
||
|
each: function (fn, scope) {
|
||
|
var scope = scope || window;
|
||
|
var fn = fn || null;
|
||
7 years ago
|
if (fn == null || typeof (fn) !== "function") {
|
||
8 years ago
|
return;
|
||
|
}
|
||
|
for (var i = 0; i < this.array.length; i++) {
|
||
|
var key = this.array[i];
|
||
|
var value = this.map[key];
|
||
|
var re = fn.call(scope, key, value, i, this.array, this.map);
|
||
|
if (re == false) {
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
|
||
|
get: function (key) {
|
||
|
return this.map[key];
|
||
|
},
|
||
|
|
||
|
toArray: function () {
|
||
|
var array = [];
|
||
|
this.each(function (key, value) {
|
||
|
array.push(value);
|
||
7 years ago
|
});
|
||
8 years ago
|
return array;
|
||
|
}
|
||
7 years ago
|
};
|
||
8 years ago
|
})();
|