static void Main(string[] args)
        {
            IntSet A = new IntSet(33);
            IntSet B = new IntSet(33);

            A.Insert(5);
            A.Insert(30);
            A.Insert(23);

            B.Insert(5);
            B.Insert(24);
            B.Insert(9);
            Console.WriteLine("A集合:{0};{1}", A.GetBitString(), A.GetElements());
            Console.WriteLine("B集合:{0};{1}", B.GetBitString(), B.GetElements());

            IntSet C;
            C = A.Union(B);
            Console.WriteLine("A并B :{0}:{1}", C.GetBitString(), C.GetElements());
            C = A.Intersect(B);
            Console.WriteLine("A交B :{0}:{1}", C.GetBitString(), C.GetElements());
            C = A.DiffSet(B);
            Console.WriteLine("A差B :{0}:{1}", C.GetBitString(), C.GetElements());
            C = A.Complement();
            Console.WriteLine("A的补:{0}:{1}", C.GetBitString(), C.GetElements());
        }
        public void set_intersection_returns_correct_result(IntSet x, IntSet y)
        {
            var intersection   = x.Intersect(y);
            var hsIntersection = new HashSet <int>(x);

            hsIntersection.IntersectWith(new HashSet <int>(y));
            CollectionAssert.AreEquivalent(hsIntersection, hsIntersection);

            set_is_optimized(intersection);
        }
Esempio n. 3
0
        public CSetSreExpr Intersection(CSetSreExpr[] inner)
        {
            IntSet cset = IntSet.All;

            foreach (var included in inner)
            {
                cset = cset.Intersect(included.Node.Characters);
            }

            return(CSet(cset));
        }
Esempio n. 4
0
        public void intersect_with_set_of_different_size(IntSet x)
        {
            var otherSetType = new BitSetType(10);
            var y            = otherSetType.Of(2, 5, 9);

            var intersection   = x.Intersect(y);
            var hsIntersection = new HashSet <int>(x);

            hsIntersection.IntersectWith(new HashSet <int>(y));
            CollectionAssert.AreEquivalent(hsIntersection, hsIntersection);

            set_is_optimized(intersection);
        }
        private void SetsShouldNotHaveCommonItems(List <IntSet> outputSets)
        {
            int len = outputSets.Count;

            for (int i = 0; i != len; ++i)
            {
                IntSet x = outputSets[i];
                for (int j = i + 1; j < len; ++j)
                {
                    IntSet y = outputSets[j];
                    CollectionAssert.IsEmpty(x.Intersect(y));
                }
            }
        }
Esempio n. 6
0
        public void equility_and_hash_to_set_with_different_size_works_according_to_the_content(IntSet x, IntSet yOfSameType)
        {
            BitSetType otherSetType = new BitSetType(10);
            var        y            = yOfSameType.Intersect(otherSetType.All);
            bool       equals       = x.Equals(y);
            bool       setEquals    = x.SetEquals(y);
            bool       hsEquals     = new HashSet <int>(x).SetEquals(new HashSet <int>(y));

            Assert.AreEqual(hsEquals, equals);
            Assert.AreEqual(hsEquals, setEquals);
            if (equals)
            {
                Assert.AreEqual(x.GetHashCode(), y.GetHashCode());
            }
            else
            {
                // Uncomment for hashing failure statistics
                // Assert.AreNotEqual(x.GetHashCode(), y.GetHashCode());
            }
        }
    public SymbolicFiniteAutomaton <TConstraint> RemoveEpsilonLoops(Func <TConstraint, TConstraint, TConstraint> disj)
    {
        var dictionary = new Dictionary <int, int>();

        foreach (var state in States)
        {
            var intSet = new IntSet(GetEpsilonClosure(state));
            dictionary[state] = intSet.Intersect(GetInvEpsilonClosure(state)).Choice;
        }
        var conditionMap = new Dictionary <Pair <int, int>, TConstraint>();
        var epsilonMoves = new HashSet <Move <TConstraint> >();

        foreach (var move in GetMoves())
        {
            var num1 = dictionary[move.SourceState];
            var num2 = dictionary[move.TargetState];
            if (move.IsEpsilon)
            {
                if (num1 != num2)
                {
                    epsilonMoves.Add(Move <TConstraint> .Epsilon(num1, num2));
                }
            }
            else
            {
                var key = new Pair <int, int>(num1, num2);
                conditionMap[key] = !conditionMap.TryGetValue(key, out var s) ? move.Condition : disj(s, move.Condition);
            }
        }
        var initialState = dictionary[InitialState];
        var finalStates  = new HashSet <int>();

        foreach (var finalState in GetFinalStates())
        {
            finalStates.Add(dictionary[finalState]);
        }
        return(Create(initialState, finalStates, EnumerateMoves(conditionMap, epsilonMoves)));
    }
Esempio n. 8
0
        public void set_intersection_returns_correct_result(IntSet x, IntSet y)
        {
            var intersection = x.Intersect(y);
            var hsIntersection = new HashSet<int>(x);
            hsIntersection.IntersectWith(new HashSet<int>(y));
            CollectionAssert.AreEquivalent(hsIntersection, hsIntersection);

            set_is_optimized(intersection);
        }
Esempio n. 9
0
        public void intersect_with_set_of_different_size(IntSet x)
        {
            var otherSetType = new BitSetType(10);
            var y = otherSetType.Of(2, 5, 9);

            var intersection = x.Intersect(y);
            var hsIntersection = new HashSet<int>(x);
            hsIntersection.IntersectWith(new HashSet<int>(y));
            CollectionAssert.AreEquivalent(hsIntersection, hsIntersection);

            set_is_optimized(intersection);
        }
Esempio n. 10
0
        public void equility_and_hash_to_set_with_different_size_works_according_to_the_content(IntSet x, IntSet yOfSameType)
        {
            BitSetType otherSetType = new BitSetType(10);
            var y = yOfSameType.Intersect(otherSetType.All);
            bool equals = x.Equals(y);
            bool setEquals = x.SetEquals(y);
            bool hsEquals = new HashSet<int>(x).SetEquals(new HashSet<int>(y));

            Assert.AreEqual(hsEquals, equals);
            Assert.AreEqual(hsEquals, setEquals);
            if (equals)
            {
                Assert.AreEqual(x.GetHashCode(), y.GetHashCode());
            }
            else
            {
                // Uncomment for hashing failure statistics
                // Assert.AreNotEqual(x.GetHashCode(), y.GetHashCode());
            }
        }