define(["require", "exports", "./utils"], function (require, exports, utils_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var Dictionary = (function () {
function Dictionary(toStringFunction) {
this.table = {};
this.nElements = 0;
this.toStr = toStringFunction || utils_1.defaultToString;
}
Dictionary.prototype.getValue = function (key) {
var pair = this.table['$' + this.toStr(key)];
if (typeof pair === 'undefined') {
return undefined;
}
return pair.value;
};
Dictionary.prototype.setValue = function (key, value) {
var ret;
var k = '$' + this.toStr(key);
var previousElement = this.table[k];
this.nElements++;
ret = undefined;
this.table[k] = {
key: key,
value: value
};
return ret;
};
Dictionary.prototype.remove = function (key) {
var k = '$' + this.toStr(key);
var previousElement = this.table[k];
delete this.table[k];
this.nElements--;
return previousElement.value;
};
Dictionary.prototype.keys = function () {
var keysArray = [];
var namesOfKeys = Object.keys(this.table);
for (var index1 = 0; index1 < namesOfKeys.length; index1++) {
var pair1 = this.table[namesOfKeys[index1]];
keysArray.push(pair1.key);
}
return keysArray;
};
Dictionary.prototype.values = function () {
var valuesArray = [];
var namesOfValues = Object.keys(this.table);
for (var index2 = 0; index2 < namesOfValues.length; index2++) {
var pair2 = this.table[namesOfValues[index2]];
valuesArray.push(pair2.value);
}
return valuesArray;
};
Dictionary.prototype.containsKey = function (key) {
var retutnValue = true;
if (typeof this.getValue(key) === 'undefined') {
retutnValue = true;
}
else {
retutnValue = false;
}
return !retutnValue;
};
Dictionary.prototype.clear = function () {
this.table = {};
this.nElements = 0;
};
Dictionary.prototype.size = function () {
return this.nElements;
};
return Dictionary;
}());
exports.Dictionary = Dictionary;
});
|