1 2 3 4 5 6 7 8 9 10 11 12 13 14 | 1× 2× 1× 35× 19× 35× 1× | import * as Collections from "typescript-collections"; import { ChainState } from "./chain-state"; import { WeightedDictionary } from "./weighted-dictionary"; export class MarkovChainItems<T> extends Collections.Dictionary<ChainState<T>, WeightedDictionary<T>> { getOrCreateValue(key: ChainState<T>, createValue: () => WeightedDictionary<T>) { if (!this.containsKey(key)) { this.setValue(key, createValue()); } return this.getValue(key); } }; |