private static void OrthohonateAt(List<IntSet> sets, IntSet x, int xIndex)
        {
            for (int j = 0; j != sets.Count; ++j)
            {
                if (j == xIndex)
                {
                    continue;
                }

                var y = sets[j];
                if (y.Count == 0)
                {
                    continue;
                }

                IntSet common, xOnly, yOnly;
                if (x.Rel(y, out xOnly, out common, out yOnly))
                {
                    x = sets[xIndex] = xOnly;
                    sets[j] = yOnly;
                    sets.Insert(xIndex + 1, common);
                    ++j;
                }
            }
        }
        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());
        }
Beispiel #3
0
        // Verifies the following properties of an IntSet:
        // 1. The integers are in order.
        // 2. There are no duplicates.
        // 3. The overall count is the same as the sum of the range counts.
        // 4. There are no empty ranges.
        // 5. No two adjacent ranges can be combined.
        public void Verify(IntSet intSet)
        {
            // iterate by ranges
            int manualCount = 0;
            IntSet.Range previousRange = null;
            foreach (IntSet.Range range in intSet.Ranges)
            {
                if (previousRange != null)
                    Assert.True(previousRange.Max + 1 < range.Min);
                previousRange = range;

                Assert.True(range.Min <= range.Max);
                Assert.True(range.Count > 0);
                Assert.True(range.PreviousItemsCount == manualCount);

                manualCount += range.Count;
            }
            Assert.True(manualCount == intSet.Count);

            // iterate by integers
            manualCount = 0;
            int previousItem = int.MinValue;
            foreach (int item in intSet)
            {
                Assert.True(previousItem < item);
                previousItem = item;
                manualCount++;
            }
            Assert.True(manualCount == intSet.Count);
        }
        public static void OrthohonalAdd(List<IntSet> sets, IntSet x)
        {
            if (x.IsEmpty || sets.IndexOf(x) >= 0)
            {
                return;
            }

            int i = sets.Count;
            sets.Add(x);
            OrthohonateAt(sets, x, i);
        }
Beispiel #5
0
        internal static int IndexOfState(this ITdfaData @this, IntSet positionSet)
        {
            int count = @this.StateCount;
            for (int i = 0; i != count; ++i)
            {
                if (@this.GetState(i).Positions.Equals(positionSet))
                {
                    return i;
                }
            }

            return -1;
        }
        public RegularTree(AstNode root)
        {
            this.EoiCharSetNode = CharSetNode.Create(EoiChar);
            this.AugmentedRoot = new CatNode(new List<AstNode> { root, EoiCharSetNode });

            var positionBuilder = new PositionBuilder();
            AugmentedRoot.Accept(positionBuilder, null);
            Positions = positionBuilder.Positions;

            EoiPosition = Positions.FindIndex(pos => pos.Characters.Contains(EoiChar));
            Debug.Assert(EoiPosition >= 0);

            var firstPosVisitor = new FirstPosGetter();
            this.FirstPos = AugmentedRoot.Accept(firstPosVisitor, 0);

            var followPosBuilder = new FollowPosBuilder(Positions);
            AugmentedRoot.Accept(followPosBuilder, 0);
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            IntSet mySet = new IntSet();
            HashSet<int> systemSet = new HashSet<int>();

            for (int i = 0; i < 10000000; i++)
            {
                int a = rand.Next(0, 100);
                mySet.Add(a);
                systemSet.Add(a);

                int b = rand.Next(0, 100);
                mySet.Remove(b);
                systemSet.Remove(b);
            }

            int[] systemSetArray = systemSet.ToArray();
            Array.Sort(systemSetArray);

            int[] mySetArray = mySet.ToArray();

            Console.WriteLine(systemSetArray.SequenceEqual(mySetArray) ?
                "test passed" : "test failed");
        }
Beispiel #8
0
 public void set_is_optimized(IntSet set)
 {
     // TODO: ??
 }
Beispiel #9
0
		protected override IntSet New(IntSet basis, bool inverted, InternalList<IntRange> ranges)
		{
			return new PGIntSet(basis.IsCharSet, ranges, inverted, false);
		}
Beispiel #10
0
		new public PGIntSet Subtract(IntSet other)
		{
			return Intersection(other, true);
		}
Beispiel #11
0
        /// <summary>
        /// Constructor</summary>
        /// <remarks>As a convenience for client code, preset the supported Unicode characters according
        /// to the computer's current culture setting. This can be overridden by the
        /// UnicodeMapper property.
        /// For 2-character language codes in ISO 639-1: http://www.loc.gov/standards/iso639-2/php/code_list.php .
        /// For unicode ranges: http://en.wikipedia.org/wiki/Summary_of_Unicode_character_assignments .
        /// The maximum possible OpenGl display list ID is ushort.MaxValue.</remarks>
        static OpenGlCore()
        {
            s_fontMap = new IntSet();

            //add ASCII, Basic Latin, and Latin-1 Supplement
            s_fontMap.AddRange(0x0000, 0x00FF);

            //add additional glyphs for some of our client languages
            string languageCode = CultureInfo.CurrentCulture.TwoLetterISOLanguageName;
            switch (languageCode)
            {
                case "ja"://Japan
                    s_fontMap.AddRange(0x30A0, 0x30FF);//Katakana
                    break;
                case "nl"://Netherlands (Dutch, Flemis)
                    s_fontMap.AddRange(0x0100, 0x024F);//Latin Extended-A, Latin Extended-B
                    s_fontMap.AddRange(0x1E00, 0x1EFF);//Latin Extended Additional
                    break;
                default:
                    break;
            }
        }
Beispiel #12
0
        public void when_set_is_empty_popany_is_not_applicable(IntSet set)
        {
            Assume.That(set.IsEmpty);

            MutableIntSet editedSet = set.EditCopy();
            int value = editedSet.PopAny();
        }
Beispiel #13
0
 public void set_reports_correct_count(IntSet set)
 {
     Assert.AreEqual(set.Count(), set.Count);
 }
Beispiel #14
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);
        }
Beispiel #15
0
        public void set_has_correct_content_after_popany_value(IntSet set)
        {
            Assume.That(!set.IsEmpty);

            MutableIntSet editedSet = set.EditCopy();
            int initialCount = editedSet.Count;
            int value = editedSet.PopAny();
            int finalCount = editedSet.Count;
            Assert.IsFalse(editedSet.Contains(value));
            Assert.AreEqual(initialCount, finalCount + 1);
        }
Beispiel #16
0
 public void set_has_correct_content_after_adding_set(IntSet set, IntSet other)
 {
     MutableIntSet editedSet = set.EditCopy();
     editedSet.AddAll(other);
     Assert.IsTrue(editedSet.IsSupersetOf(other));
     Assert.IsTrue(set.Union(other).SetEquals(editedSet));
     IntSet result = editedSet.CompleteAndDestroy();
     Assert.IsTrue(result.IsSupersetOf(other));
     Assert.IsTrue(set.Union(other).SetEquals(result));
 }
Beispiel #17
0
 public void set_reports_correct_count(IntSet set)
 {
     Assert.AreEqual(set.Count(), set.Count);
 }
Beispiel #18
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());
            }
        }
Beispiel #19
0
        public void set_has_correct_content_after_adding_value(IntSet set, int value)
        {
            MutableIntSet editedSet = set.EditCopy();
            Assert.AreEqual(set.Contains(value), editedSet.Contains(value));
            editedSet.Add(value);
            Assert.IsTrue(editedSet.Contains(value));

            Assert.IsTrue(editedSet.Contains(value));
            Assert.IsTrue(set.Union(IntSet.Of(value)).SetEquals(editedSet));
            IntSet result = editedSet.CompleteAndDestroy();
            Assert.IsTrue(result.Contains(value));
            Assert.IsTrue(set.IsSubsetOf(result));
            Assert.IsTrue(set.Union(IntSet.Of(value)).SetEquals(result));
        }
Beispiel #20
0
        public void adding_existing_values_to_set_does_not_change_set(IntSet x, int value)
        {
            x = x.Union(IntSet.Of(value));
            int countBeforeValueDuplication = x.Count;
            Assert.IsTrue(x.Contains(value));
            x.Union(IntSet.Of(value));
            Assert.IsTrue(x.Contains(value));

            Assert.AreEqual(countBeforeValueDuplication, x.Count);
        }
Beispiel #21
0
 public void set_has_correct_content_after_removing_value(IntSet set, int value)
 {
     MutableIntSet editedSet = set.EditCopy();
     int initialCount = editedSet.Count;
     editedSet.Remove(value);
     int finalCount = editedSet.Count;
     Assert.IsFalse(editedSet.Contains(value));
     Assert.IsTrue(finalCount == initialCount || finalCount + 1 == initialCount);
 }
Beispiel #22
0
        public void complement_returns_correct_result(IntSet set)
        {
            var got = set.Complement();
            foreach (var item in set)
            {
                Assert.IsTrue(!got.Contains(item));
            }

            int countToCheck = 1000;
            foreach (var item in got)
            {
                Assert.IsFalse(set.Contains(item));
                if (--countToCheck == 0)
                {
                    break;
                }
            }

            set_is_optimized(got);
        }
Beispiel #23
0
 public void set_is_optimized(IntSet set)
 {
     // TODO: ??
 }
Beispiel #24
0
        public void complement_with_set_of_different_size_returns_correct_result(IntSet set)
        {
            var otherSetType = new BitSetType(10);
            var y = otherSetType.Of(2, 5, 9);

            var got = set.Complement(y);
            foreach (var item in set)
            {
                Assert.IsTrue(!got.Contains(item));
            }

            foreach (var item in y)
            {
                Assert.IsTrue(got.Contains(item) || set.Contains(item));
            }

            int countToCheck = 1000;
            foreach (var item in got)
            {
                Assert.IsFalse(set.Contains(item));
                if (--countToCheck == 0)
                {
                    break;
                }
            }

            set_is_optimized(got);
        }
Beispiel #25
0
        public void set_union_returns_correct_result(IntSet x, IntSet y)
        {
            var union = x.Union(y);
            var hsUnion = new HashSet<int>(x);
            hsUnion.UnionWith(new HashSet<int>(y));
            CollectionAssert.AreEquivalent(hsUnion, union);

            set_is_optimized(union);
        }
Beispiel #26
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());
            }
        }
Beispiel #27
0
        public void addall_with_set_of_different_size(IntSet set)
        {
            var otherSetType = new BitSetType(10);
            var other = otherSetType.Of(2, 5, 9);

            MutableIntSet editedSet = set.EditCopy();
            editedSet.AddAll(other);
            Assert.IsTrue(editedSet.IsSupersetOf(other));
            Assert.IsTrue(set.Union(other).SetEquals(editedSet));
            IntSet result = editedSet.CompleteAndDestroy();
            Assert.IsTrue(result.IsSupersetOf(other));
            Assert.IsTrue(set.Union(other).SetEquals(result));
        }
Beispiel #28
0
        public void equility_and_hash_works_according_to_the_content(IntSet x, IntSet y)
        {
            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());
            }
        }
Beispiel #29
0
		new public PGIntSet Intersection(IntSet other, bool subtract = false, bool subtractThis = false)
		{
			return (PGIntSet)base.Intersection(other, subtract, subtractThis);
		}
Beispiel #30
0
        public void identical_sets_are_equal()
        {
            var sets = new IntSet[]
            {
                IntSet.Of(10),
                IntSet.Of(10),
                IntSet.Range(10, 10),
                IntSet.Range(10, 10),
                IntSet.Ranges(
                    new []
                    {
                        new IntInterval(10, 10),
                        new IntInterval(10, 10),
                        new IntInterval(10, 10),
                    }),
            };

            for (int i = 0; i != sets.Length; ++i)
            {
                var x = sets[i];
                for (int j = 0; j != sets.Length; ++j)
                {
                    var y = sets[j];
                    Assert.IsTrue(x.Equals(y));
                    Assert.IsTrue(y.Equals(x));
                    Assert.IsTrue(x.SetEquals(y));
                    Assert.IsTrue(y.SetEquals(x));
                }
            }
        }
Beispiel #31
0
		public PGIntSet Optimize(IntSet dontcare)
		{
			return (PGIntSet)base.Optimize(dontcare);
		}
Beispiel #32
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);
        }
Beispiel #33
0
		public PGIntSet Union(IntSet other)
		{
			return (PGIntSet)base.Union(other, true);
		}
Beispiel #34
0
 static void Type(IntSet followers)
 {
     //Type = "int" | "void" | "bool" | "char" .
     Accept(FirstType, "Invalid Type");
 }