자바스 크립트 해쉬테이블(Hashtables in javascript)
-
function naiveHashing()
-
{
-
var keys = [];
-
var values = [];
-
this.save = function (key, value) {
-
var existingIndex = ko.utils.arrayIndexOf(keys, key);
-
if (existingIndex >= 0) values[existingIndex] = value;
-
else {
-
keys.push(key);
-
values.push(value);
-
}
-
};
-
this.get = function (key) {
-
var existingIndex = ko.utils.arrayIndexOf(keys, key);
-
return (existingIndex >= 0) ? values[existingIndex] : undefined;
-
};
-
}
-
function libHashing()
-
{
-
var ht = new Hashtable();
-
-
this.save = function(key, value) {
-
ht.put(key, value);
-
};
-
-
this.get = function(key) {
-
return ht.get(key);
-
};
-
}
-
function jsonHashing()
-
{
-
var obj = {};
-
-
this.save = function(key, value) {
-
obj[JSON.stringify(key)] = value;
-
};
-
-
this.get = function(key) {
-
return obj[JSON.stringify(key)];
-
};
-
}