all files / src/ markov-chain-items.ts

100% Statements 9/9
100% Branches 2/2
100% Functions 2/2
100% Lines 7/7
1 2 3 4 5 6 7 8 9 10 11 12 13 14         35× 19×   35×    
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);
    }
};