public void TestSetDifference(Set<string> setFirst, Set<string> setSecond, Set<string> resultSet) { setFirst.Difference(setSecond); var iteratorFirst = setFirst.GetEnumerator(); var resultIterator = resultSet.GetEnumerator(); while (iteratorFirst.MoveNext() && resultIterator.MoveNext()) { Assert.AreEqual(iteratorFirst.Current, resultIterator.Current); } }
/*** Given the DFA set of states, generate the DFAmin set of states. ***/ private ArrayList createDFASets(Set DFAset, Set chrSet) { // array of all set of DFA states ArrayList arr = new ArrayList(); // to tracks transitions SetHashtable hashSet = new SetHashtable(); // to track states Set emtySet = new Set(); Set finalStates = new Set(); Set otherStates = new Set(); // 1) divide on final and non-final states criteria foreach (object objState in DFAset) { AutomataState state = (AutomataState)objState; if (!state.IsFinalState) { otherStates.addElement(state); } else { finalStates.addElement(state); } } // 2) fill arr with states (final + eventually other) if (otherStates.NumOfElement > 0) { arr.Add(otherStates); } arr.Add(finalStates); // 3) iterate on set of symbols IEnumerator chrIterator = chrSet.GetEnumerator(); chrIterator.Reset(); while (chrIterator.MoveNext()) { // get transition symbol string sym = chrIterator.Current.ToString(); int i = 0; while (i < arr.Count) { Set setToBePartitioned = (Set)arr[i++]; // cannot divide a set with once or less elements if (setToBePartitioned.NumOfElement == 0 || setToBePartitioned.NumOfElement == 1) { continue; } foreach (object objState in setToBePartitioned) { AutomataState state = (AutomataState)objState; List<AutomataState> statesList = state.getAllDestStatesWithStringTransaction(sym.ToString()); if (statesList != null && statesList.Count > 0) { // could be only once AutomataState stateTransionTo = statesList[0]; // get the set that contains "stateTransitionTo" Set foundedSet = findInWhichSet(arr, stateTransionTo); hashSet.Add(foundedSet, state); } else { // if there are no transition, add a transition to emptyset hashSet.Add(emtySet, state); } } if (hashSet.Count > 1) // means some states transition into different groups { arr.Remove(setToBePartitioned); foreach (DictionaryEntry de in hashSet) { Set setValue = (Set)de.Value; arr.Add(setValue); } // restart from begin (reset to initial loop state) i = 0; chrIterator.Reset(); } hashSet.Clear(); } } return arr; }
/// <summary> /// Enumeration is, by definition, not thread-safe. Use a <c>lock</c> on the <c>SyncRoot</c> /// to synchronize the entire enumeration process. /// </summary> /// <returns></returns> public sealed override IEnumerator GetEnumerator() { return(_basisSet.GetEnumerator()); }