/// <summary> /// Returns a new (deterministic and minimal) automaton that accepts the union of the given /// set of strings. The input character sequences are internally sorted in-place, so the /// input array is modified. @see StringUnionOperations. /// </summary> /// <param name="strings">The strings.</param> /// <returns></returns> public static Automaton MakeStringUnion(params char[][] strings) { if (strings.Length == 0) { return(MakeEmpty()); } Array.Sort(strings, StringUnionOperations.LexicographicOrderComparer); var a = new Automaton(); a.Initial = StringUnionOperations.Build(strings); a.IsDeterministic = true; a.Reduce(); a.RecomputeHashCode(); return(a); }
/// <summary> /// Returns a new (deterministic) automaton that accepts a single character in the given set. /// </summary> /// <param name="set">The set.</param> /// <returns></returns> public static Automaton MakeCharSet(string set) { if (set.Length == 1) { return(MakeChar(set[0])); } var a = new Automaton(); var s1 = new State(); var s2 = new State(); a.Initial = s1; s2.Accept = true; foreach (char t in set) { s1.Transitions.Add(new Transition(t, s2)); } a.IsDeterministic = true; a.Reduce(); return(a); }
/// <summary> /// Returns a new (deterministic and minimal) automaton that accepts the union of the given /// set of strings. The input character sequences are internally sorted in-place, so the /// input array is modified. @see StringUnionOperations. /// </summary> /// <param name="strings">The strings.</param> /// <returns></returns> public static Automaton MakeStringUnion(params char[][] strings) { if (strings.Length == 0) { return MakeEmpty(); } Array.Sort(strings, StringUnionOperations.LexicographicOrderComparer); var a = new Automaton(); a.Initial = StringUnionOperations.Build(strings); a.IsDeterministic = true; a.Reduce(); a.RecomputeHashCode(); return a; }
/// <summary> /// Returns a new (deterministic) automaton that accepts a single character in the given set. /// </summary> /// <param name="set">The set.</param> /// <returns></returns> public static Automaton MakeCharSet(string set) { if (set.Length == 1) { return MakeChar(set[0]); } var a = new Automaton(); var s1 = new State(); var s2 = new State(); a.Initial = s1; s2.Accept = true; foreach (char t in set) { s1.Transitions.Add(new Transition(t, s2)); } a.IsDeterministic = true; a.Reduce(); return a; }