public virtual void Test2a() { var baseName = GetBaseName(); // LogUtil.allOn(true); DeleteBase(baseName); var persister = GetPersister(baseName); IBTreeMultipleValuesPerKey tree = new OdbBtreeMultiple(20, persister); var start0 = OdbTime.GetCurrentTimeInMs(); for (var i = 0; i < Size; i++) { tree.Insert(i + 1, "value " + (i + 1)); } // println("Commiting"); persister.Close(); var end0 = OdbTime.GetCurrentTimeInMs(); // println("insert of "+SIZE+" elements in BTREE = " + // (end0-start0)+"ms"); // println("end Commiting"); persister = GetPersister(baseName); // println("reloading btree"); tree = (IBTreeMultipleValuesPerKey)persister.LoadBTree(tree.GetId()); // println("end reloading btree , size="+tree.size()); AssertEquals(Size, tree.GetSize()); long totalSearchTime = 0; long oneSearchTime = 0; long minSearchTime = 10000; long maxSearchTime = -1; for (var i = 0; i < Size; i++) { var start = OdbTime.GetCurrentTimeInMs(); var o = tree.Search(i + 1); var end = OdbTime.GetCurrentTimeInMs(); AssertEquals("value " + (i + 1), o[0]); oneSearchTime = (end - start); // println("Search time for "+o+" = "+oneSearchTime); if (oneSearchTime > maxSearchTime) { maxSearchTime = oneSearchTime; } if (oneSearchTime < minSearchTime) { minSearchTime = oneSearchTime; } totalSearchTime += oneSearchTime; } persister.Close(); // println("total search time="+totalSearchTime + // " - mean st="+((double)totalSearchTime/SIZE)); // println("min search time="+minSearchTime + " - max="+maxSearchTime); // Median search time must be smaller than 1ms DeleteBase(baseName); AssertTrue(totalSearchTime < 1 * Size); }
public virtual void Test1() { DeleteBase("btree45.ndb"); var odb = Open("btree45.ndb"); var storageEngine = ((global::NDatabase.Odb)odb).GetStorageEngine(); var persister = new LazyOdbBtreePersister(storageEngine); IBTreeMultipleValuesPerKey tree = new OdbBtreeMultiple(3, persister); tree.Insert(1, new MyObject("Value 1")); tree.Insert(20, new MyObject("Value 20")); tree.Insert(25, new MyObject("Value 25")); tree.Insert(29, new MyObject("Value 29")); tree.Insert(21, new MyObject("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>; AssertEquals("Value 21", values[0].ToString()); AssertEquals(0, tree.GetRoot().GetNbChildren()); tree.Insert(45, new MyObject("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()); persister.Close(); odb = Open("btree45.ndb"); storageEngine = ((global::NDatabase.Odb)odb).GetStorageEngine(); persister = new LazyOdbBtreePersister(storageEngine); tree = (IBTreeMultipleValuesPerKey)persister.LoadBTree(tree.GetId()); AssertEquals(6, tree.GetSize()); // println(tree.getRoot()); var o = (MyObject)tree.Search(20)[0]; AssertEquals("Value 20", o.GetName()); o = (MyObject)tree.Search(29)[0]; AssertEquals("Value 29", o.GetName()); o = (MyObject)tree.Search(45)[0]; AssertEquals("Value 45", o.GetName()); odb.Close(); DeleteBase("btree45.ndb"); }