Example #1
0
 public virtual void TestSplit()
 {
     NeoDatis.Btree.IBTree tree = GetBTree(2);
     tree.Insert(10, "Key 10");
     tree.Insert(100, "Key 100");
     NeoDatis.Btree.IBTreeNodeOneValuePerKey c1    = GetBTreeNode(tree, "child 1");
     NeoDatis.Btree.IBTreeNodeOneValuePerKey c2    = GetBTreeNode(tree, "child 2");
     NeoDatis.Btree.IBTreeNodeOneValuePerKey node1 = (NeoDatis.Btree.IBTreeNodeOneValuePerKey
                                                      )tree.GetRoot();
     node1.SetChildAt(c1, 0);
     node1.SetChildAt(c2, 1);
     node1.SetNbKeys(2);
     node1.SetNbChildren(2);
     c1.SetKeyAndValueAt(1, "Key 1", 0);
     c1.SetKeyAndValueAt(2, "Key 2", 1);
     c1.SetKeyAndValueAt(3, "Key 3", 2);
     c1.SetNbKeys(3);
     AssertEquals(0, c1.GetNbChildren());
     tree.Split(node1, c1, 0);
     AssertEquals(3, node1.GetNbKeys());
     AssertEquals(3, node1.GetNbChildren());
     AssertEquals(2, node1.GetKeyAndValueAt(0).GetKey());
     AssertEquals(10, node1.GetKeyAndValueAt(1).GetKey());
     AssertEquals(100, node1.GetKeyAndValueAt(2).GetKey());
     NeoDatis.Btree.IBTreeNodeOneValuePerKey c1New = (NeoDatis.Btree.IBTreeNodeOneValuePerKey
                                                      )node1.GetChildAt(0, false);
     AssertEquals(1, c1New.GetNbKeys());
     AssertEquals(0, c1New.GetNbChildren());
     AssertEquals(1, c1New.GetKeyAt(0));
     AssertEquals(null, c1New.GetKeyAt(1));
     AssertEquals(null, c1New.GetKeyAt(2));
     AssertEquals(node1, c1New.GetParent());
     NeoDatis.Btree.IBTreeNodeOneValuePerKey c1bis = (NeoDatis.Btree.IBTreeNodeOneValuePerKey
                                                      )node1.GetChildAt(1, false);
     AssertEquals(1, c1bis.GetNbKeys());
     AssertEquals(0, c1bis.GetNbChildren());
     AssertEquals(3, c1bis.GetKeyAt(0));
     AssertEquals(node1, c1bis.GetParent());
     AssertEquals(null, c1bis.GetKeyAt(1));
     AssertEquals(null, c1bis.GetKeyAt(2));
     NeoDatis.Btree.IBTreeNodeOneValuePerKey c2New = (NeoDatis.Btree.IBTreeNodeOneValuePerKey
                                                      )node1.GetChildAt(2, false);
     AssertEquals(c2, c2New);
 }
Example #2
0
 public virtual void Testsearch10()
 {
     NeoDatis.Btree.IBTreeSingleValuePerKey btree = GetBTree(3);
     for (int i = 0; i < 10; i++)
     {
         btree.Insert(i, "key " + i);
     }
     AssertEquals(10, btree.GetSize());
     AssertEquals("key 1", btree.Search(1));
     AssertEquals("key 9", btree.Search(9));
     NeoDatis.Btree.IBTreeNodeOneValuePerKey child3 = (NeoDatis.Btree.IBTreeNodeOneValuePerKey
                                                       )btree.GetRoot().GetChildAt(2, false);
     AssertEquals(4, child3.GetNbKeys());
     AssertEquals(6, child3.GetKeyAt(0));
     AssertEquals(7, child3.GetKeyAt(1));
     AssertEquals(8, child3.GetKeyAt(2));
     AssertEquals(9, child3.GetKeyAt(3));
     AssertEquals(null, child3.GetKeyAt(4));
 }