Example #1
0
        public void InsertComplexLeftRightRotation()
        {
            var t = Tree(8, 3, 11, 2, 5, 9, 12, 1, 4, 6);

            AssertTree(t, "8L=[3=[2L=1|*]|[5=4|6]]|[11=9|12]");
            UnsafeOrderedCollection.Insert(t, 7);
            AssertTree(t, "5=[3L=[2L=1|*]|4]|[8=[6R=*|7]|[11=9|12]]");
        }
Example #2
0
        public void InsertComplexRightRotation()
        {
            var t = Tree(6, 7, 4, 5, 3);

            AssertTree(t, "6L=[4=3|5]|7");
            UnsafeOrderedCollection.Insert(t, 1);
            AssertTree(t, "4=[3L=1|*]|[6=5|7]");
        }
Example #3
0
        public void InsertComplexRightLeftRotation()
        {
            var t = Tree(5, 3, 10, 2, 4, 8, 11, 7, 9, 12);

            AssertTree(t, "5R=[3=2|4]|[10=[8=7|9]|[11R=*|12]]");
            UnsafeOrderedCollection.Insert(t, 6);
            AssertTree(t, "8=[5=[3=2|4]|[7L=6|*]]|[10R=9|[11R=*|12]]");
        }
Example #4
0
        public void InsertComplexLeftRotation()
        {
            var t = Tree(3, 2, 5, 4, 6);

            AssertTree(t, "3R=2|[5=4|6]");
            UnsafeOrderedCollection.Insert(t, 7);
            AssertTree(t, "5=[3=2|4]|[6R=*|7]");
        }
Example #5
0
        public void InsertSimpleLeftRightRotation()
        {
            var t = Tree(2, 3);

            AssertTree(t, "2R=*|3");
            UnsafeOrderedCollection.Insert(t, 1);
            AssertTree(t, "2=1|3");
            UnsafeOrderedCollection.Free(t);
        }
Example #6
0
        public void InsertSimpleRightRotation()
        {
            var t = Tree(3, 2);

            AssertTree(t, "3L=2|*");
            UnsafeOrderedCollection.Insert(t, 1);
            AssertTree(t, "2=1|3");
            UnsafeOrderedCollection.Free(t);
        }
Example #7
0
        public void InsertSimpleLeftRotation()
        {
            var t = Tree(1, 2);

            AssertTree(t, "1R=*|2");
            UnsafeOrderedCollection.Insert(t, 3);
            AssertTree(t, "2=1|3");
            UnsafeOrderedCollection.Free(t);
        }
Example #8
0
        static UnsafeOrderedCollection *Tree(params int[] values)
        {
            var c = UnsafeOrderedCollection.Allocate <int>(values.Length * 2);

            for (int i = 0; i < values.Length; ++i)
            {
                UnsafeOrderedCollection.Insert(c, values[i]);
            }

            return(c);
        }
Example #9
0
        public void InsertCase2()
        {
            UnsafeOrderedCollection *t;

            t = Tree(_insertCase2);
            AssertTree(t, "20L=[4=3|9]|26");
            UnsafeOrderedCollection.Insert(t, 15);
            AssertTree(t, "9=[4L=3|*]|[20=15|26]");

            t = Tree(_insertCase2);
            UnsafeOrderedCollection.Insert(t, 8);
            AssertTree(t, "9=[4=3|8]|[20R=*|26]");
        }
Example #10
0
        public void InsertCase1()
        {
            UnsafeOrderedCollection *t;

            t = Tree(_insertCase1);
            AssertTree(t, "20L=4|*");
            UnsafeOrderedCollection.Insert(t, 15);
            AssertTree(t, "15=4|20");

            t = Tree(_insertCase1);
            UnsafeOrderedCollection.Insert(t, 8);
            AssertTree(t, "8=4|20");
        }
Example #11
0
        public void InsertCase3()
        {
            UnsafeOrderedCollection *t;

            t = Tree(_insertCase3);
            AssertTree(t, "20L=[4=[3L=2|*]|[9=7|11]]|[26=21|30]");
            UnsafeOrderedCollection.Insert(t, 15);
            AssertTree(t, "9=[4L=[3L=2|*]|7]|[20=[11R=*|15]|[26=21|30]]");

            t = Tree(_insertCase3);
            AssertTree(t, "20L=[4=[3L=2|*]|[9=7|11]]|[26=21|30]");
            UnsafeOrderedCollection.Insert(t, 8);
            AssertTree(t, "9=[4=[3L=2|*]|[7R=*|8]]|[20R=11|[26=21|30]]");
        }
Example #12
0
 public static void Add <T>(UnsafeOrderedSet *set, T item)
     where T : unmanaged, IComparable <T>
 {
     UnsafeOrderedCollection.Insert <T>(&set->_collection, item);
 }