コード例 #1
0
 public virtual void Test1()
 {
     var degree = 3;
     IBTreeMultipleValuesPerKey tree = new InMemoryBTreeMultipleValuesPerKey(degree);
     tree.Insert(1, "Value 1");
     tree.Insert(20, "Value 20");
     tree.Insert(25, "Value 25");
     tree.Insert(29, "Value 29");
     tree.Insert(21, "Value 21");
     AssertEquals(5, tree.GetRoot().GetNbKeys());
     AssertEquals(0, tree.GetRoot().GetNbChildren());
     AssertEquals(21, tree.GetRoot().GetMedian().GetKey());
     var values = tree.GetRoot().GetMedian().GetValue() as List<object>;
     Assert.That(values, Is.Not.Null);
     AssertEquals("Value 21", values[0].ToString());
     AssertEquals(0, tree.GetRoot().GetNbChildren());
     // println(tree.getRoot());
     tree.Insert(45, "Value 45");
     AssertEquals(2, tree.GetRoot().GetNbChildren());
     AssertEquals(1, tree.GetRoot().GetNbKeys());
     AssertEquals(21, tree.GetRoot().GetKeyAt(0));
     var valuesAsObjectAt = tree.GetRoot().GetValueAsObjectAt(0) as List<object>;
     AssertEquals("Value 21", valuesAsObjectAt[0].ToString());
     // println(tree.getRoot());
     var o = tree.Search(20);
     AssertEquals("Value 20", o[0]);
     o = tree.Search(29);
     AssertEquals("Value 29", o[0]);
     o = tree.Search(45);
     AssertEquals("Value 45", o[0]);
 }
コード例 #2
0
        public virtual void Test1()
        {
            var degree = 3;
            IBTreeMultipleValuesPerKey tree = new InMemoryBTreeMultipleValuesPerKey(degree);

            tree.Insert(1, "Value 1");
            tree.Insert(20, "Value 20");
            tree.Insert(25, "Value 25");
            tree.Insert(29, "Value 29");
            tree.Insert(21, "Value 21");
            AssertEquals(5, tree.GetRoot().GetNbKeys());
            AssertEquals(0, tree.GetRoot().GetNbChildren());
            AssertEquals(21, tree.GetRoot().GetMedian().GetKey());
            var values = tree.GetRoot().GetMedian().GetValue() as List <object>;

            Assert.That(values, Is.Not.Null);
            AssertEquals("Value 21", values[0].ToString());
            AssertEquals(0, tree.GetRoot().GetNbChildren());
            // println(tree.getRoot());
            tree.Insert(45, "Value 45");
            AssertEquals(2, tree.GetRoot().GetNbChildren());
            AssertEquals(1, tree.GetRoot().GetNbKeys());
            AssertEquals(21, tree.GetRoot().GetKeyAt(0));
            var valuesAsObjectAt = tree.GetRoot().GetValueAsObjectAt(0) as List <object>;

            AssertEquals("Value 21", valuesAsObjectAt[0].ToString());
            // println(tree.getRoot());
            var o = tree.Search(20);

            AssertEquals("Value 20", o[0]);
            o = tree.Search(29);
            AssertEquals("Value 29", o[0]);
            o = tree.Search(45);
            AssertEquals("Value 45", o[0]);
        }
コード例 #3
0
        public virtual void Test4()
        {
            var degree = 3;
            IBTreeMultipleValuesPerKey tree1 = new InMemoryBTreeMultipleValuesPerKey(degree);
            tree1.Insert(1, "A");
            // tree.insert(new Integer(2),"B");
            tree1.Insert(3, "C");
            tree1.Insert(4, "D");
            tree1.Insert(5, "E");
            IBTreeMultipleValuesPerKey tree2 = new InMemoryBTreeMultipleValuesPerKey(degree);
            tree2.Insert(10, "J");
            tree2.Insert(11, "K");
            IBTreeMultipleValuesPerKey tree3 = new InMemoryBTreeMultipleValuesPerKey(degree);
            tree3.Insert(14, "N");
            tree3.Insert(15, "O");
            IBTreeMultipleValuesPerKey tree4 = new InMemoryBTreeMultipleValuesPerKey(degree);
            tree4.Insert(18, "R");
            tree4.Insert(19, "S");
            tree4.Insert(20, "T");
            tree4.Insert(21, "U");
            tree4.Insert(22, "V");
            IBTreeMultipleValuesPerKey tree5 = new InMemoryBTreeMultipleValuesPerKey(degree);
            tree5.Insert(25, "Y");
            tree5.Insert(26, "Z");
            IBTreeMultipleValuesPerKey tree6 = new InMemoryBTreeMultipleValuesPerKey(degree);
            tree6.Insert(7, "G");
            tree6.Insert(13, "M");
            tree6.Insert(16, "P");
            tree6.Insert(24, "X");
            tree6.GetRoot().SetChildAt(tree1.GetRoot(), 0);
            tree6.GetRoot().SetChildAt(tree2.GetRoot(), 1);
            tree6.GetRoot().SetChildAt(tree3.GetRoot(), 2);
            tree6.GetRoot().SetChildAt(tree4.GetRoot(), 3);
            tree6.GetRoot().SetChildAt(tree5.GetRoot(), 4);
            tree6.GetRoot().SetNbChildren(5);
            // println("Test 4");
            tree6.Insert(2, "B");

            var valuesAsObjectAt1 = tree6.GetRoot().GetChildAt(0, true).GetValueAsObjectAt(1) as List<object>;
            AssertEquals("B", valuesAsObjectAt1[0].ToString());
            tree6.Insert(17, "Q");

            AssertEquals(5, tree6.GetRoot().GetNbKeys());

            var valuesAsObjectAt2 = tree6.GetRoot().GetChildAt(3, true).GetValueAsObjectAt(0) as List<object>;
            AssertEquals("Q", valuesAsObjectAt2[0].ToString());
            var valuesAsObjectAt3 = tree6.GetRoot().GetChildAt(3, true).GetValueAsObjectAt(1) as List<object>;
            AssertEquals("R", valuesAsObjectAt3[0].ToString());
            var valuesAsObjectAt4 = tree6.GetRoot().GetChildAt(3, true).GetValueAsObjectAt(2) as List<object>;
            AssertEquals("S", valuesAsObjectAt4[0].ToString());

            var valuesAsObjectAt5 = tree6.GetRoot().GetChildAt(4, true).GetValueAsObjectAt(0) as List<object>;
            AssertEquals("U", valuesAsObjectAt5[0].ToString());
            var valuesAsObjectAt6 = tree6.GetRoot().GetChildAt(4, true).GetValueAsObjectAt(1) as List<object>;
            AssertEquals("V", valuesAsObjectAt6[0].ToString());
            tree6.Insert(12, "L");

            AssertEquals(1, tree6.GetRoot().GetNbKeys());
            AssertEquals(2, tree6.GetRoot().GetChildAt(0, true).GetNbKeys());

            var valuesAsObjectAt7 = tree6.GetRoot().GetChildAt(0, true).GetValueAsObjectAt(0) as List<object>;
            AssertEquals("G", valuesAsObjectAt7[0].ToString());
            var valuesAsObjectAt8 = tree6.GetRoot().GetChildAt(0, true).GetValueAsObjectAt(1) as List<object>;
            AssertEquals("M", valuesAsObjectAt8[0].ToString());

            var valuesAsObjectAt9 =
                tree6.GetRoot().GetChildAt(0, true).GetChildAt(1, true).GetValueAsObjectAt(0) as List<object>;
            AssertEquals("J", valuesAsObjectAt9[0].ToString());
            var valuesAsObjectAt10 =
                tree6.GetRoot().GetChildAt(0, true).GetChildAt(1, true).GetValueAsObjectAt(1) as List<object>;
            AssertEquals("K", valuesAsObjectAt10[0].ToString());
            var valuesAsObjectAt11 =
                tree6.GetRoot().GetChildAt(0, true).GetChildAt(1, true).GetValueAsObjectAt(2) as List<object>;
            AssertEquals("L", valuesAsObjectAt11[0].ToString());
            tree6.Insert(6, "F");

            AssertEquals(1, tree6.GetRoot().GetNbKeys());
            AssertEquals(3, tree6.GetRoot().GetChildAt(0, true).GetNbKeys());
            AssertEquals(2, tree6.GetRoot().GetChildAt(0, true).GetChildAt(0, true).GetNbKeys());

            var valuesAsObjectAt12 =
                tree6.GetRoot().GetChildAt(0, true).GetChildAt(0, true).GetValueAsObjectAt(0) as List<object>;
            AssertEquals("A", valuesAsObjectAt12[0].ToString());
            var valuesAsObjectAt13 =
                tree6.GetRoot().GetChildAt(0, true).GetChildAt(0, true).GetValueAsObjectAt(1) as List<object>;
            AssertEquals("B", valuesAsObjectAt13[0].ToString());

            var valuesAsObjectAt14 =
                tree6.GetRoot().GetChildAt(1, true).GetChildAt(2, true).GetValueAsObjectAt(1) as List<object>;
            AssertEquals("Z", valuesAsObjectAt14[0].ToString());
        }
コード例 #4
0
        public virtual void Test4()
        {
            var degree = 3;
            IBTreeMultipleValuesPerKey tree1 = new InMemoryBTreeMultipleValuesPerKey(degree);

            tree1.Insert(1, "A");
            // tree.insert(new Integer(2),"B");
            tree1.Insert(3, "C");
            tree1.Insert(4, "D");
            tree1.Insert(5, "E");
            IBTreeMultipleValuesPerKey tree2 = new InMemoryBTreeMultipleValuesPerKey(degree);

            tree2.Insert(10, "J");
            tree2.Insert(11, "K");
            IBTreeMultipleValuesPerKey tree3 = new InMemoryBTreeMultipleValuesPerKey(degree);

            tree3.Insert(14, "N");
            tree3.Insert(15, "O");
            IBTreeMultipleValuesPerKey tree4 = new InMemoryBTreeMultipleValuesPerKey(degree);

            tree4.Insert(18, "R");
            tree4.Insert(19, "S");
            tree4.Insert(20, "T");
            tree4.Insert(21, "U");
            tree4.Insert(22, "V");
            IBTreeMultipleValuesPerKey tree5 = new InMemoryBTreeMultipleValuesPerKey(degree);

            tree5.Insert(25, "Y");
            tree5.Insert(26, "Z");
            IBTreeMultipleValuesPerKey tree6 = new InMemoryBTreeMultipleValuesPerKey(degree);

            tree6.Insert(7, "G");
            tree6.Insert(13, "M");
            tree6.Insert(16, "P");
            tree6.Insert(24, "X");
            tree6.GetRoot().SetChildAt(tree1.GetRoot(), 0);
            tree6.GetRoot().SetChildAt(tree2.GetRoot(), 1);
            tree6.GetRoot().SetChildAt(tree3.GetRoot(), 2);
            tree6.GetRoot().SetChildAt(tree4.GetRoot(), 3);
            tree6.GetRoot().SetChildAt(tree5.GetRoot(), 4);
            tree6.GetRoot().SetNbChildren(5);
            // println("Test 4");
            tree6.Insert(2, "B");

            var valuesAsObjectAt1 = tree6.GetRoot().GetChildAt(0, true).GetValueAsObjectAt(1) as List <object>;

            AssertEquals("B", valuesAsObjectAt1[0].ToString());
            tree6.Insert(17, "Q");

            AssertEquals(5, tree6.GetRoot().GetNbKeys());

            var valuesAsObjectAt2 = tree6.GetRoot().GetChildAt(3, true).GetValueAsObjectAt(0) as List <object>;

            AssertEquals("Q", valuesAsObjectAt2[0].ToString());
            var valuesAsObjectAt3 = tree6.GetRoot().GetChildAt(3, true).GetValueAsObjectAt(1) as List <object>;

            AssertEquals("R", valuesAsObjectAt3[0].ToString());
            var valuesAsObjectAt4 = tree6.GetRoot().GetChildAt(3, true).GetValueAsObjectAt(2) as List <object>;

            AssertEquals("S", valuesAsObjectAt4[0].ToString());

            var valuesAsObjectAt5 = tree6.GetRoot().GetChildAt(4, true).GetValueAsObjectAt(0) as List <object>;

            AssertEquals("U", valuesAsObjectAt5[0].ToString());
            var valuesAsObjectAt6 = tree6.GetRoot().GetChildAt(4, true).GetValueAsObjectAt(1) as List <object>;

            AssertEquals("V", valuesAsObjectAt6[0].ToString());
            tree6.Insert(12, "L");

            AssertEquals(1, tree6.GetRoot().GetNbKeys());
            AssertEquals(2, tree6.GetRoot().GetChildAt(0, true).GetNbKeys());

            var valuesAsObjectAt7 = tree6.GetRoot().GetChildAt(0, true).GetValueAsObjectAt(0) as List <object>;

            AssertEquals("G", valuesAsObjectAt7[0].ToString());
            var valuesAsObjectAt8 = tree6.GetRoot().GetChildAt(0, true).GetValueAsObjectAt(1) as List <object>;

            AssertEquals("M", valuesAsObjectAt8[0].ToString());

            var valuesAsObjectAt9 =
                tree6.GetRoot().GetChildAt(0, true).GetChildAt(1, true).GetValueAsObjectAt(0) as List <object>;

            AssertEquals("J", valuesAsObjectAt9[0].ToString());
            var valuesAsObjectAt10 =
                tree6.GetRoot().GetChildAt(0, true).GetChildAt(1, true).GetValueAsObjectAt(1) as List <object>;

            AssertEquals("K", valuesAsObjectAt10[0].ToString());
            var valuesAsObjectAt11 =
                tree6.GetRoot().GetChildAt(0, true).GetChildAt(1, true).GetValueAsObjectAt(2) as List <object>;

            AssertEquals("L", valuesAsObjectAt11[0].ToString());
            tree6.Insert(6, "F");

            AssertEquals(1, tree6.GetRoot().GetNbKeys());
            AssertEquals(3, tree6.GetRoot().GetChildAt(0, true).GetNbKeys());
            AssertEquals(2, tree6.GetRoot().GetChildAt(0, true).GetChildAt(0, true).GetNbKeys());

            var valuesAsObjectAt12 =
                tree6.GetRoot().GetChildAt(0, true).GetChildAt(0, true).GetValueAsObjectAt(0) as List <object>;

            AssertEquals("A", valuesAsObjectAt12[0].ToString());
            var valuesAsObjectAt13 =
                tree6.GetRoot().GetChildAt(0, true).GetChildAt(0, true).GetValueAsObjectAt(1) as List <object>;

            AssertEquals("B", valuesAsObjectAt13[0].ToString());

            var valuesAsObjectAt14 =
                tree6.GetRoot().GetChildAt(1, true).GetChildAt(2, true).GetValueAsObjectAt(1) as List <object>;

            AssertEquals("Z", valuesAsObjectAt14[0].ToString());
        }