aboutsummaryrefslogtreecommitdiff
path: root/lib/utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/utils.js')
-rw-r--r--lib/utils.js18
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/utils.js b/lib/utils.js
index 27b79753..15eed9ba 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -247,16 +247,30 @@ function makePredicate(words) {
function Dictionary() {
this._values = Object.create(null);
+ this._size = 0;
};
Dictionary.prototype = {
- set: function(key, val) { return this._values["$" + key] = val, this },
+ set: function(key, val) {
+ if (!this.has(key)) ++this._size;
+ this._values["$" + key] = val;
+ return this;
+ },
get: function(key) { return this._values["$" + key] },
- del: function(key) { return delete this._values["$" + key], this },
+ del: function(key) {
+ if (this.has(key)) {
+ --this._size;
+ delete this._values["$" + key];
+ }
+ return this;
+ },
has: function(key) { return ("$" + key) in this._values },
each: function(f) {
for (var i in this._values)
f(this._values[i], i.substr(1));
},
+ size: function() {
+ return this._size;
+ },
map: function(f) {
var ret = [];
for (var i in this._values)