public static bool SearchKey(System.IComparable key, NeoDatis.Btree.IBTreeNodeOneValuePerKey node) { if (!on) { return(false); } for (int i = 0; i < node.GetNbKeys(); i++) { if (node.GetKeyAndValueAt(i).GetKey().CompareTo(key) == 0) { return(true); } } return(false); }
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); }
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)); }
public virtual void TestInsert3() { NeoDatis.Btree.IBTreeSingleValuePerKey btree = GetBTree(3); btree.Insert(1, "key 1"); btree.Insert(2, "key 2"); btree.Insert(3, "key 3"); btree.Insert(4, "key 4"); btree.Insert(5, "key 5"); btree.Insert(6, "key 6"); AssertEquals(6, btree.GetSize()); AssertEquals("key 1", btree.Search(1)); AssertEquals("key 2", btree.Search(2)); AssertEquals("key 3", btree.Search(3)); AssertEquals("key 4", btree.Search(4)); AssertEquals("key 5", btree.Search(5)); AssertEquals("key 6", btree.Search(6)); AssertEquals(2, btree.GetRoot().GetNbChildren()); // child 1 should be [1,2] NeoDatis.Btree.IBTreeNodeOneValuePerKey child1 = (NeoDatis.Btree.IBTreeNodeOneValuePerKey )btree.GetRoot().GetChildAt(0, false); AssertEquals(2, child1.GetNbKeys()); AssertEquals(0, child1.GetNbChildren()); AssertEquals("key 1", child1.GetKeyAndValueAt(0).GetValue()); AssertEquals(1, child1.GetKeyAndValueAt(0).GetKey()); // child 2 should be [4,5,6] NeoDatis.Btree.IBTreeNodeOneValuePerKey child2 = (NeoDatis.Btree.IBTreeNodeOneValuePerKey )btree.GetRoot().GetChildAt(1, false); AssertEquals(3, child2.GetNbKeys()); AssertEquals(0, child2.GetNbChildren()); AssertEquals("key 4", child2.GetKeyAndValueAt(0).GetValue()); AssertEquals("key 5", child2.GetKeyAndValueAt(1).GetValue()); AssertEquals("key 6", child2.GetKeyAndValueAt(2).GetValue()); // child 2 should be null NeoDatis.Btree.IBTreeNodeOneValuePerKey child3 = (NeoDatis.Btree.IBTreeNodeOneValuePerKey )btree.GetRoot().GetChildAt(2, false); AssertEquals(null, child3); }