UNPKG

markov-typescript

Version:

A Markov Chain library written in Typescript.

57 lines 2.1 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); var Collections = require("typescript-collections"); var WeightedDictionary = (function (_super) { __extends(WeightedDictionary, _super); function WeightedDictionary(toStrFunction) { var _this = _super.call(this, toStrFunction) || this; _this._totalWeight = 0; return _this; } Object.defineProperty(WeightedDictionary.prototype, "totalWeight", { get: function () { return this._totalWeight; }, enumerable: true, configurable: true }); WeightedDictionary.prototype.setValue = function (key, value) { var prevVal = _super.prototype.setValue.call(this, key, value); if (prevVal) { this._totalWeight -= prevVal; } if (value) { this._totalWeight += value; } return prevVal; }; WeightedDictionary.prototype.incrementValue = function (key, value) { var newWeight = value; if (this.containsKey(key)) { newWeight += this.getValue(key); } ; return this.setValue(key, newWeight); }; WeightedDictionary.prototype.remove = function (key) { var val = _super.prototype.remove.call(this, key); if (val) { this._totalWeight -= val; } return val; }; return WeightedDictionary; }(Collections.Dictionary)); exports.WeightedDictionary = WeightedDictionary; ; //# sourceMappingURL=weighted-dictionary.js.map