public IDictionary <FA, int[]> FillInputTransitionRangesGroupedByState(IDictionary <FA, int[]> result = null) { var working = new Dictionary <FA, List <KeyValuePair <int, int> > >(); foreach (var trns in InputTransitions) { List <KeyValuePair <int, int> > l; if (!working.TryGetValue(trns.Value, out l)) { l = new List <KeyValuePair <int, int> >(); working.Add(trns.Value, l); } l.Add(trns.Key); } if (null == result) { result = new Dictionary <FA, int[]>(); } foreach (var item in working) { item.Value.Sort((x, y) => { var c = x.Key.CompareTo(y.Key); if (0 != c) { return(c); } return(x.Value.CompareTo(y.Value)); }); RangeUtility.NormalizeSortedRangeList(item.Value); result.Add(item.Key, RangeUtility.FromPairs(item.Value)); } return(result); }
public static FA Set(int[] ranges, int accept = -1) { var result = new FA(); var final = new FA(true, accept); var pairs = new List <KeyValuePair <int, int> >(RangeUtility.ToPairs(ranges)); pairs.Sort((x, y) => { return(x.Key.CompareTo(y.Key)); }); RangeUtility.NormalizeSortedRangeList(pairs); foreach (var pair in pairs) { result.AddInputTransition(pair, final); } return(result); }