private StateNode _NodeNextState(TransitionKey tk, StateNode state) { StateNode stateNew = state.NextState(tk, false); if (stateNew == null) { stateNew = _stateRoot.NextState(tk, false); } return(stateNew != null ? stateNew : _stateRoot); }
// Adds a new object to a given sequence of transition keys in the // graph. Traverses existing transitions and adds new states and // transitions as necessary. public void Add(IEnumerable <TransitionKey> rgtkTerminal, Terminal obj) { StateNode state = _stateRoot; foreach (TransitionKey tk in rgtkTerminal) { state = state.NextState(tk, true); } state.AddTerminalObj(obj); }
// Removes a terminal object associated with a given sequence of // transition keys from the graph. This will also remove any state // nodes that as a result wind up without any useful information // in them (either a transition to a new state, or a list of objects // associated with a terminal state). private StateNode _StateRemove(TransitionKey[] rgtkTerminal, int itk, Terminal obj, StateNode stateCur) { if (itk < rgtkTerminal.Length) { TransitionKey tk = rgtkTerminal[itk]; StateNode stateNext = stateCur.NextState(tk, false); if (stateNext == null) { throw new ArgumentException("String not found in graph", "rgtkTerminal"); } stateNext = _StateRemove(rgtkTerminal, itk + 1, obj, stateNext); if (stateNext == null) { stateCur.RemoveLink(tk); if (stateCur.Clink == 0) { stateCur = null; } } } else { if (stateCur.CobjTerminal == 0) { throw new ArgumentException("String not found in graph", "rgtkTerminal"); } stateCur.RemoveTerminalObj(obj); if (stateCur.CobjTerminal == 0) { stateCur = null; } } return(stateCur); }