@tannerntannern/budgeteer
Version:
A specialized constraint solver for budget flows
49 lines (48 loc) • 1.59 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
/**
* A Map with two keys as opposed to one. Order does matter, so `map.get(k1, k2) !== map.get(k2, k1)` for example.
*/
var TwoKeyMap = /** @class */ (function () {
function TwoKeyMap() {
/**
* Internal storage for the TwoKeyMap, which is just a Map of Maps.
*/
this.values = new Map();
}
/**
* Creates a relationship between `[k1, k2]` and `v`, overwriting if one already exists.
*/
TwoKeyMap.prototype.set = function (k1, k2, val) {
if (!this.values.get(k1))
this.values.set(k1, new Map());
this.values.get(k1).set(k2, val);
};
/**
* Gets the value associated with `[k1, k2]`.
*/
TwoKeyMap.prototype.get = function (k1, k2) {
if (!this.values.get(k1))
return null;
else
return this.values.get(k1).get(k2);
};
/**
* Similar to JavaScript's `Map.prototype.forEach`, but with slightly different arguments.
*/
TwoKeyMap.prototype.forEach = function (handler) {
this.values.forEach(function (internalMap, externalKey) {
internalMap.forEach(function (value, internalKey) {
handler(externalKey, internalKey, value);
});
});
};
/**
* Clears all entries from the TwoKeyMap.
*/
TwoKeyMap.prototype.clear = function () {
this.values.clear();
};
return TwoKeyMap;
}());
exports.TwoKeyMap = TwoKeyMap;