public bool Equals(DfaStateBuilder <TLetter> other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(this.NfaStates.Select(s => s.Id).SetEqual(other.NfaStates.Select(s => s.Id)) && this.transitions.Equals(other.transitions)); }
private static bool GetStateBuilder(Dictionary <string, DfaStateBuilder <TLetter> > dfaStates, Id <DfaState <TLetter> > firstId, IEnumerable <NfaState <TLetter> > states, out DfaStateBuilder <TLetter> builder) { var stateArray = states.Distinct().OrderBy(s => s.Id).ToArray(); var key = string.Join("|", stateArray.Select(s => XmlConvert.ToString(s.Id.ToInt32()))); if (string.IsNullOrEmpty(key)) { key = "EOF"; } if (!dfaStates.TryGetValue(key, out builder)) { builder = new DfaStateBuilder <TLetter>(dfaStates.Count + firstId.ToInt32(), key, stateArray); dfaStates.Add(key, builder); return(true); } Debug.Assert(stateArray.SetEqual(builder.NfaStates)); return(false); }
public void SetTransition(Range <TLetter> letter, DfaStateBuilder <TLetter> target) { this.transitions.Add(letter, target); }
public void ReplaceTransition(Func <DfaStateBuilder <TLetter>, bool> predicate, DfaStateBuilder <TLetter> replacement) { for (var i = 0; i < this.transitions.Values.Count; i++) { if (predicate(this.transitions.Values[i])) { Debug.Assert(Equals(this.transitions.Values[i], replacement)); this.transitions.Values[i] = replacement; } } }