-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dictionary.js
36 lines (31 loc) · 953 Bytes
/
Dictionary.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
var UTIL = UTIL || {};
/**
* Generates a new Dictionary object
*
* @classDescription Dictionaries store key value pairs in an easy to use
* format such you can always get a list of keys without extra properties.
* @param {Object} startValues An object which contains initial sets of
* keys with their values.
*/
UTIL.Dictionary = function Dictionary(startValues) {
this.values = startValues || {};
this.count = 0;
};
UTIL.Dictionary.prototype.store = function(name, value) {
this.values[name] = value;
this.count++;
};
UTIL.Dictionary.prototype.contains = function(name) {
return Object.prototype.hasOwnProperty.call(this.values, name);
};
UTIL.Dictionary.prototype.remove = function(key) {
if(this.contains(key)) delete this.values[key];
this.count--;
};
UTIL.Dictionary.prototype.lookup = function(name) {
return this.values[name];
};
UTIL.Dictionary.prototype.clear = function() {
this.values = {};
this.count = 0;
}