/// <inheritdoc/> protected internal override void AddTerminalInternal(ChainState <T> state, int weight) { for (var orderTarget = this.Order; orderTarget >= 1; orderTarget--) { if (orderTarget == this.Order) { base.AddTerminalInternal(state, weight); } else { if (orderTarget < state.Count) { state = new ChainState <T>(state.Skip(state.Count - orderTarget)); } this.chains[this.Order - orderTarget - 1].AddTerminalInternal(state, weight); } } }
/// <inheritdoc/> public override void Add(ChainState <T> state, T next, int weight) { if (state == null) { throw new ArgumentNullException(nameof(state)); } for (var orderTarget = this.Order; orderTarget >= 1; orderTarget--) { if (orderTarget == this.Order) { base.Add(state, next, weight); } else { if (orderTarget < state.Count) { state = new ChainState <T>(state.Skip(state.Count - orderTarget)); } this.chains[this.Order - orderTarget - 1].Add(state, next, weight); } } }
private int GetDesiredOrderTarget(ref ChainState <T> state, out Dictionary <T, int> nextStates) { for (var orderTarget = this.Order; ; orderTarget--) { if (orderTarget == this.Order) { nextStates = base.GetNextStatesInternal(state); } else { if (orderTarget < state.Count) { state = new ChainState <T>(state.Skip(state.Count - orderTarget)); } nextStates = this.chains[this.Order - orderTarget - 1].GetNextStatesInternal(state); } if (nextStates?.Count >= this.desiredNumNextStates || orderTarget <= 1) { return(orderTarget); } } }