コード例 #1
0
ファイル: TestODBLazyBTree.cs プロジェクト: spolnik/ndatabase
        public virtual void Test01()
        {
            var baseName = GetBaseName();
            DeleteBase(baseName);
            var persister = GetPersister(baseName);
            IBTree tree = new OdbBtreeMultiple(2, persister);
            var start = OdbTime.GetCurrentTimeInMs();
            for (var i = 0; i < Size; i++)
                tree.Insert(i + 1, "value " + (i + 1));

            var end = OdbTime.GetCurrentTimeInMs();
            Println("time/object=" + (end - start) / (float) Size);

            AssertTrue((end - start) < 3000);

            AssertEquals(Size, tree.GetSize());
            var iterator = tree.Iterator<object>(OrderByConstants.OrderByAsc);
            var j = 0;
            while (iterator.MoveNext())
            {
                var o = iterator.Current;
                AssertEquals("value " + (j + 1), o);
                j++;
                if (j % 10 == 0)
                    Println(j);
            }
            persister.Close();
            DeleteBase(baseName);
        }
コード例 #2
0
ファイル: TestODBLazyBTree.cs プロジェクト: spolnik/ndatabase
 public virtual void Test1()
 {
     var baseName = GetBaseName();
     var persister = GetPersister(baseName);
     IBTree tree = new OdbBtreeMultiple(2, persister);
     var start = OdbTime.GetCurrentTimeInMs();
     for (var i = 0; i < Size; i++)
         tree.Insert(i + 1, "value " + (i + 1));
     var end = OdbTime.GetCurrentTimeInMs();
     Println(end - start);
     if (testPerformance)
         AssertTrue((end - start) < 0.34 * Size);
     // println("insert of "+SIZE+" elements in BTREE = " +
     // (end-start)+"ms");
     // persister.close();
     // persister = getPersister();
     AssertEquals(Size, tree.GetSize());
     var iterator = tree.Iterator<object>(OrderByConstants.OrderByAsc);
     var j = 0;
     while (iterator.MoveNext())
     {
         var o = iterator.Current;
         AssertEquals("value " + (j + 1), o);
         j++;
         if (j % 10 == 0)
             Println(j);
     }
     persister.Close();
     DeleteBase(baseName);
 }
コード例 #3
0
ファイル: TestPersister.cs プロジェクト: spolnik/ndatabase
 public virtual void TestDirectSave()
 {
     DeleteBase("btree46.ndb");
     var odb = Open("btree46.ndb");
     IBTree tree = new OdbBtreeMultiple(3, new InMemoryPersister());
     IBTreeNodeMultipleValuesPerKey node = new OdbBtreeNodeMultiple(tree);
     odb.Store(node);
     for (var i = 0; i < 4; i++)
     {
         node.SetKeyAndValueAt(new KeyAndValue(i + 1, "String" + (i + 1)), i);
         odb.Store(node);
     }
     odb.Close();
     DeleteBase("btree46.ndb");
 }
コード例 #4
0
ファイル: TestPersister.cs プロジェクト: danfma/NDB
        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");
        }
コード例 #5
0
ファイル: TestODBLazyBTree.cs プロジェクト: spolnik/ndatabase
 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);
 }
コード例 #6
0
ファイル: TestODBLazyBTree.cs プロジェクト: spolnik/ndatabase
 public virtual void Test2()
 {
     var baseName = GetBaseName();
     var persister = GetPersister(baseName);
     IBTree tree = new OdbBtreeMultiple(2, persister);
     for (var i = 0; i < Size; i++)
         tree.Insert(i + 1, "value " + (i + 1));
     AssertEquals(Size, tree.GetSize());
     var iterator = tree.Iterator<object>(OrderByConstants.OrderByDesc);
     var j = 0;
     while (iterator.MoveNext())
     {
         var o = iterator.Current;
         // println(o);
         j++;
         if (j == Size)
             AssertEquals("value " + 1, o);
     }
     persister.Close();
     DeleteBase(baseName);
 }
コード例 #7
0
ファイル: TestODBLazyBTree.cs プロジェクト: spolnik/ndatabase
        public virtual void Test1a()
        {
            var baseName = GetBaseName();

            var persister = GetPersister(baseName);
            IBTree tree = new OdbBtreeMultiple(2, persister);
            for (var i = 0; i < Size; i++)
                tree.Insert(i + 1, "value " + (i + 1));
            // println(new BTreeDisplay().build(tree,true).toString());
            persister.Close();
            persister = GetPersister(baseName);
            tree = persister.LoadBTree(tree.GetId());
            // println(new BTreeDisplay().build(tree,true).toString());
            AssertEquals(Size, tree.GetSize());
            var iterator = tree.Iterator<object>(OrderByConstants.OrderByAsc);
            var j = 0;
            while (iterator.MoveNext())
            {
                var o = iterator.Current;
                AssertEquals("value " + (j + 1), o);
                j++;
                if (j == Size)
                    AssertEquals("value " + Size, o);
            }
            persister.Close();
            DeleteBase(baseName);
        }