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]); }
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]); }
public virtual void Test2() { var degree = 10; IBTreeMultipleValuesPerKey tree = new InMemoryBTreeMultipleValuesPerKey(degree); for (var i = 0; i < 50000; i++) tree.Insert(i, "Value " + i); AssertEquals("Value 0", tree.Search(0)[0]); AssertEquals("Value 1000", tree.Search(1000)[0]); AssertEquals("Value 2000", tree.Search(2000)[0]); AssertEquals("Value 3000", tree.Search(3000)[0]); // tree.resetNbRead(); AssertEquals("Value 4999", tree.Search(4999)[0]); }
public virtual void TestNonUniqueKey() { var degree = 3; IBTreeMultipleValuesPerKey tree1 = new InMemoryBTreeMultipleValuesPerKey(degree); tree1.Insert(1, "A"); tree1.Insert(1, "AA"); tree1.Insert(1, "AAA"); AssertEquals(3, tree1.Search(1).Count); AssertEquals("A", tree1.Search(1)[0].ToString()); AssertEquals("AA", tree1.Search(1)[1].ToString()); AssertEquals("AAA", tree1.Search(1)[2].ToString()); AssertEquals(3, tree1.GetSize()); }
public virtual void Test2() { var degree = 10; IBTreeMultipleValuesPerKey tree = new InMemoryBTreeMultipleValuesPerKey(degree); for (var i = 0; i < 50000; i++) { tree.Insert(i, "Value " + i); } AssertEquals("Value 0", tree.Search(0)[0]); AssertEquals("Value 1000", tree.Search(1000)[0]); AssertEquals("Value 2000", tree.Search(2000)[0]); AssertEquals("Value 3000", tree.Search(3000)[0]); // tree.resetNbRead(); AssertEquals("Value 4999", tree.Search(4999)[0]); }
public virtual void TestString2() { var size = 300; var max = 0; IBTreeMultipleValuesPerKey tree = new InMemoryBTreeMultipleValuesPerKey(5); for (var i = 1; i < size; i++) { for (var j = 1; j < size; j++) { var key = ((i + 1) * size + j).ToString(); var value = (i * j).ToString(); tree.Insert(key, value); if (i * j > max) { max = i * j; } } } // println("max = " + max); for (var i = 1; i < size; i++) { for (var j = 1; j < size; j++) { var key = ((i + 1) * size + j).ToString(); var value = (i * j).ToString(); var p = tree.Search(key); AssertEquals(value, p[0]); } } }
public virtual void TestInsertUsingInt2() { var size = 8000; IBTreeMultipleValuesPerKey tree = new InMemoryBTreeMultipleValuesPerKey(5); for (var i = 1; i < size; i++) { tree.Insert(i, i.ToString()); } var l = tree.Search(1); AssertEquals("1", l[0].ToString()); l = tree.Search(1000); AssertEquals("1000", l[0]); l = tree.Search(2000); AssertEquals("2000", l[0]); l = tree.Search(9800); AssertNull(l); l = tree.Search(99999); AssertEquals(null, l); }
public virtual void Test5() { var degree = 40; IBTreeMultipleValuesPerKey tree = new InMemoryBTreeMultipleValuesPerKey(degree); var a0 = OdbTime.GetCurrentTimeInMs(); for (var i = 0; i < 500000; i++) { tree.Insert(i, "Value " + i); } var a1 = OdbTime.GetCurrentTimeInMs(); Console.WriteLine("insert time = {0}", (a1 - a0)); AssertEquals("Value 0", tree.Search(0)[0].ToString()); AssertEquals("Value 1000", tree.Search(1000)[0].ToString()); AssertEquals("Value 2000", tree.Search(2000)[0].ToString()); AssertEquals("Value 48000", tree.Search(48000)[0].ToString()); // tree.resetNbRead(); var t0 = OdbTime.GetCurrentTimeInMs(); for (var i = 0; i < 100000; i++) { AssertEquals("Value 490000", tree.Search(490000)[0].ToString()); } var t1 = OdbTime.GetCurrentTimeInMs(); // tree.resetNbRead(); AssertEquals("Value 490000", tree.Search(490000)[0].ToString()); Console.WriteLine("Search in {0} ms", t1 - t0); }
public virtual void TestString1() { IBTreeMultipleValuesPerKey tree = new InMemoryBTreeMultipleValuesPerKey(5); tree.Insert("50", "50"); tree.Insert("40", "40"); tree.Insert("30", "30"); tree.Insert("20", "20"); tree.Insert("10", "10"); tree.Insert("15", "15"); tree.Insert("25", "25"); tree.Insert("35", "35"); tree.Insert("21", "21"); tree.Insert("22", "22"); tree.Insert("23", "23"); var p = tree.Search("22"); AssertEquals("22", p[0]); }
public virtual void TestInsertUsingInt1() { IBTreeMultipleValuesPerKey tree = new InMemoryBTreeMultipleValuesPerKey(5); tree.Insert(50, "50"); tree.Insert(40, "40"); tree.Insert(30, "30"); tree.Insert(20, "20"); tree.Insert(10, "10"); tree.Insert(15, "15"); tree.Insert(25, "25"); tree.Insert(35, "35"); tree.Insert(21, "21"); tree.Insert(22, "22"); tree.Insert(23, "23"); var l = tree.Search(22); AssertEquals("22", l[0]); }
public virtual void TestNonUniqueKey2() { var degree = 3; IBTreeMultipleValuesPerKey tree1 = new InMemoryBTreeMultipleValuesPerKey(degree); tree1.Insert(1, "A"); tree1.Insert(1, "AA"); tree1.Insert(1, "AAA"); tree1.Insert(1, "BBB"); var c = tree1.Search(1); AssertEquals(4, c.Count); var iterator = c.GetEnumerator(); iterator.MoveNext(); AssertEquals("A", iterator.Current); iterator.MoveNext(); AssertEquals("AA", iterator.Current); AssertEquals(4, tree1.GetSize()); AssertEquals("A", c[0].ToString()); AssertEquals("AA", c[1].ToString()); AssertEquals("AAA", c[2].ToString()); AssertEquals("BBB", c[3].ToString()); }
public virtual void TestString2() { var size = 300; var max = 0; IBTreeMultipleValuesPerKey tree = new InMemoryBTreeMultipleValuesPerKey(5); for (var i = 1; i < size; i++) { for (var j = 1; j < size; j++) { var key = ((i + 1) * size + j).ToString(); var value = (i * j).ToString(); tree.Insert(key, value); if (i * j > max) max = i * j; } } // println("max = " + max); for (var i = 1; i < size; i++) { for (var j = 1; j < size; j++) { var key = ((i + 1) * size + j).ToString(); var value = (i * j).ToString(); var p = tree.Search(key); AssertEquals(value, p[0]); } } }
public virtual void TestInsertUsingInt2() { var size = 8000; IBTreeMultipleValuesPerKey tree = new InMemoryBTreeMultipleValuesPerKey(5); for (var i = 1; i < size; i++) tree.Insert(i, i.ToString()); var l = tree.Search(1); AssertEquals("1", l[0].ToString()); l = tree.Search(1000); AssertEquals("1000", l[0]); l = tree.Search(2000); AssertEquals("2000", l[0]); l = tree.Search(9800); AssertNull(l); l = tree.Search(99999); AssertEquals(null, l); }
public virtual void Test5() { var degree = 40; IBTreeMultipleValuesPerKey tree = new InMemoryBTreeMultipleValuesPerKey(degree); var a0 = OdbTime.GetCurrentTimeInMs(); for (var i = 0; i < 500000; i++) tree.Insert(i, "Value " + i); var a1 = OdbTime.GetCurrentTimeInMs(); Console.WriteLine("insert time = {0}", (a1 - a0)); AssertEquals("Value 0", tree.Search(0)[0].ToString()); AssertEquals("Value 1000", tree.Search(1000)[0].ToString()); AssertEquals("Value 2000", tree.Search(2000)[0].ToString()); AssertEquals("Value 48000", tree.Search(48000)[0].ToString()); // tree.resetNbRead(); var t0 = OdbTime.GetCurrentTimeInMs(); for (var i = 0; i < 100000; i++) AssertEquals("Value 490000", tree.Search(490000)[0].ToString()); var t1 = OdbTime.GetCurrentTimeInMs(); // tree.resetNbRead(); AssertEquals("Value 490000", tree.Search(490000)[0].ToString()); Console.WriteLine("Search in {0} ms", t1 - t0); }