public static void CopyTo(this IAutomaton @this, IAutomatonBuilder builder, out int oldNewStartState, out IEnumerable <int> oldNewAcceptingStates) { var stateMapping = new Dictionary <int, int>(); for (var state = 0; state < @this.StateCount; state++) { stateMapping.Add(state, builder.AddState()); } foreach (var kv in @this.TransitionsBySource) { var source = stateMapping[kv.Key]; var transition = kv.Value; foreach (var target in transition) { foreach (var x in target.Select(v => stateMapping[v])) { builder.AddTransition(source, target.Key, x); } } } oldNewStartState = stateMapping[@this.StartState]; oldNewAcceptingStates = @this.AcceptingStates.Select(s => stateMapping[s]).ToArray(); }
public static void AddTransition(this IAutomatonBuilder @this, int source, char c, int target) { var charset = new CharSet(c); @this.AddTransition(source, charset, target); }
public static void AddEpsilonTransition(this IAutomatonBuilder @this, int source, int target) { @this.AddTransition(source, CharSet.Epsilon, target); }