From: Koichi KAMICHI Date: Wed, 23 Feb 2011 05:30:56 +0000 (+0000) Subject: Use hash instead of array. X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8ec9d61c13e5ad147779fb84828f31cbbdbbbab2;p=chise%2Fkage.git Use hash instead of array. --- diff --git a/engine/buhin.js b/engine/buhin.js index f1cd8ba..3fa0442 100755 --- a/engine/buhin.js +++ b/engine/buhin.js @@ -1,38 +1,21 @@ function Buhin(number){ // method - function push(name, data){ // void - var temp = new Object(); - temp.name = name; - temp.data = data; - this.array.push(temp); - } - Buhin.prototype.push = push; - function set(name, data){ // void - var temp = new Object(); - temp.name = name; - temp.data = data; - for(var i = 0; i < this.array.length; i++){ - if(this.array[i].name == name){ - this.array.splice(i, 1); - } - } - this.array.push(temp); + this.hash[name] = data; } + Buhin.prototype.push = set; Buhin.prototype.set = set; function search(name){ // string - for(var i = 0; i < this.array.length; i++){ - if(this.array[i].name == name){ - return this.array[i].data; - } + if(this.hash[name]){ + return this.hash[name]; } return ""; // no data } Buhin.prototype.search = search; // property - this.array = new Array(); + this.hash = {}; // initialize // no operation