X-Git-Url: https://jfr.im/git/irc/quakenet/qwebirc.git/blobdiff_plain/9e99acfd96c74ff373639b6805b95027664feaac..015ab79ac65cca3c99282e6c735412131f92e4f9:/js/qhash.js diff --git a/js/qhash.js b/js/qhash.js index f76199b..f18e0fc 100644 --- a/js/qhash.js +++ b/js/qhash.js @@ -1,150 +1,150 @@ -QHash = function(def) { - this.__map = {}; - this.length = 0; - - if(def !== undefined) { - var h = Object.prototype.hasOwnProperty; - for (var k in def) { - if(!h.call(def, k)) - continue; - this.put(k, def[k]); - } - } -}; - -QHash.prototype.__toKey = function(key) { - if(typeof(key) !== "string") - throw new TypeError("Not a string: " + key); - return key + "$"; -}; - -QHash.prototype.get = function(key) { - return this.__map[this.__toKey(key)]; -}; - -QHash.prototype.put = function(key, value) { - key = this.__toKey(key); - - var exists = key in this.__map; - var oldValue = this.__map[key]; - - this.__map[key] = value; - - if(!exists) { - this.length++; - return null; - } - - return oldValue; -}; - -QHash.prototype.contains = function(key) { - return this.__toKey(key) in this.__map; -}; - -QHash.prototype.remove = function(key) { - key = this.__toKey(key); - - var exists = key in this.__map; - if(!exists) - return null; - - var oldValue = this.__map[key]; - delete this.__map[key]; - this.length--; - - return oldValue; -}; - -QHash.prototype.each = function(fn, def) { - var h = Object.prototype.hasOwnProperty; - var m = this.__map; - for(var k in m) { - if(!h.call(m, k)) - continue; - - var break_ = fn.call(def, k.substr(0, k.length - 1), m[k]) !== undefined; - if(break_) - return break_; - } -}; - -QHash.prototype.isEmpty = function() { - return this.length == 0; -}; - -QHash.prototype.map = function(fn, def) { - var l = []; - this.each(function(k, v) { - l.push(fn.call(def, k, v)); - }); - return l; -}; - -QHash.prototype.keys = function() { - return this.map(function(k) { return k; }); -}; - -QHash.prototype.values = function() { - return this.map(function(k, v) { return v; }); -}; - -QHash.prototype.items = function() { - return this.map(function(k, v) { return [k, v]; }); -}; - -QHash.prototype.toString = function() { - var m = this.map(function(k, v) { - return k + "=" + v; - }, this); - - return "{QHash length=" + this.length + " map={" + m + "}}"; -}; - -QSet = function() { - this.__map = new QHash(); - - this.length = 0; - for(var i=0;i