示例#1
0
        public void GetEqualOrMoreTest3()
        {
            RedBlackTreeWithIndexAccess tree = new RedBlackTreeWithIndexAccess();

            tree.RB_Insert(new TestObjectForEqualOrMore("zhu0", 0));
            tree.RB_Insert(new TestObjectForEqualOrMore("zhu4", 4));
            tree.RB_Insert(new TestObjectForEqualOrMore("zhu2", 2));
            tree.RB_Insert(new TestObjectForEqualOrMore("zhu1", 5));
            tree.RB_Insert(new TestObjectForEqualOrMore("zhu3", 3));
            tree.RB_Insert(new TestObjectForEqualOrMore("zhu1", 6));
            tree.RB_Insert(new TestObjectForEqualOrMore("zhu1", 7));

            RBNodeIndexAccess node = tree.GetEqualOrMore(new TestObjectForEqualOrMore("zhu1", 0), null);

            Assert.AreEqual("zhu1", ((TestObjectForEqualOrMore)node.Key).Str);
            Assert.AreEqual(5, ((TestObjectForEqualOrMore)node.Key).Num);

            node = tree.GetNext(node);

            Assert.AreEqual("zhu1", ((TestObjectForEqualOrMore)node.Key).Str);
            Assert.AreEqual(6, ((TestObjectForEqualOrMore)node.Key).Num);

            node = tree.GetNext(node);

            Assert.AreEqual("zhu1", ((TestObjectForEqualOrMore)node.Key).Str);
            Assert.AreEqual(7, ((TestObjectForEqualOrMore)node.Key).Num);
        }
示例#2
0
        public void GetEqualOrMoreTest2()
        {
            RedBlackTreeWithIndexAccess tree = new RedBlackTreeWithIndexAccess();

            tree.RB_Insert("zhu0");
            tree.RB_Insert("zhu4");
            tree.RB_Insert("zhu2");
            tree.RB_Insert("zhu3");
            RBNodeIndexAccess node = tree.GetEqualOrMore("zhu1", null);

            Assert.AreEqual("zhu2", (string)node.Key);
            node = tree.GetNext(node);
            Assert.AreEqual("zhu3", (string)node.Key);
            node = tree.GetNext(node);
            Assert.AreEqual("zhu4", (string)node.Key);
            node = tree.GetNext(node);
            Assert.AreEqual(null, node);
        }
示例#3
0
        public void GetEqualOrMoreTest4()
        {
            RedBlackTreeWithIndexAccess tree = new RedBlackTreeWithIndexAccess();

            for (int i = 0; i < 100000; i++)
            {
                tree.RB_Insert(i);
            }

            for (int i = 10000; i < 10010; i++)
            {
                tree.RB_Delete(i);
                RBNodeIndexAccess node = tree.GetEqualOrMore(i, null);
                Assert.AreEqual(i + 1, (int)node.Key);
                for (int j = i + 2; j < 100000; j++)
                {
                    node = tree.GetNext(node);
                    Assert.AreEqual(j, (int)node.Key);
                }
            }
        }