1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- Hashtable = function() {
- this._hash = new Object();
- this.onPropertyChanged = function(added, updated, deleted) { }
- this.add = function(key, value) {
- if (typeof (key) != "undefined") {
- if (this.contains(key) == false) {
- this._hash[key] = typeof (value) == "undefined" ? null : value;
- this.onPropertyChanged([{ 'key': key, 'value': value}], [], []);
- return true;
- } else {
- this.setvalue(key,value);
- }
- } else {
- return false;
- }
- }
- this.remove = function(key) {
- var deleted = [{ 'key': key, 'value': this._hash[key]}];
- delete this._hash[key];
- this.onPropertyChanged([], [], deleted);
- }
- this.count = function() { var i = 0; for (var k in this._hash) { i++; } return i; }
- this.items = function(key) { return this._hash[key]; }
- this.contains = function(key) { return typeof (this._hash[key]) != "undefined"; }
- this.clear = function(lazy) {
- var deleted = [];
- if (lazy == undefined || !lazy)
- deleted = this.allitems();
- for (var k in this._hash) {
- delete this._hash[k];
- }
- if (lazy == undefined || !lazy)
- this.onPropertyChanged([], [], deleted);
- }
- this.values = function() {
- var list = new Array();
- for (var k in this._hash)
- list[list.length] = this._hash[k];
- return list;
- }
- this.keys = function() {
- var list = new Array();
- for (var k in this._hash)
- list[list.length] = k;
- return list;
- }
- this.setvalue = function(key, value) { this._hash[key] = value; this.onPropertyChanged(this); }
- this.allitems = function() {
- var list = new Array();
- for (var k in this._hash) {
- list[list.length] = { key: k, value: this._hash[k] };
- }
- return list;
- }
- }
|