From 8ec9d61c13e5ad147779fb84828f31cbbdbbbab2 Mon Sep 17 00:00:00 2001 From: Koichi KAMICHI Date: Wed, 23 Feb 2011 05:30:56 +0000 Subject: [PATCH] Use hash instead of array. --- engine/buhin.js | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) 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 -- 1.7.10.4