Example #1
0
        public void InsertAndDeletePageBenchmark()
        {
            IntHashSet numbers = new IntHashSet();
            const int queueSize = 4000;
            TestKey keyFactory = new TestKey();
            IBTree bTree = new /*BTree*/OmniaMeaBTree( _indexFileName, keyFactory );
            using( bTree )
            {
                bTree.Open( );

                Queue queue = new Queue( queueSize );
                for ( int i = 0; i < queueSize; i++ )
                {
                    TestKey testKey = new TestKey( GetUniqueRand( numbers ) );
                    queue.Enqueue( testKey );
                    bTree.InsertKey( testKey, (int)testKey.Key );
                }
                int time = System.Environment.TickCount;
                for ( int i = 0; i < 100000; i++ )
                {
                    TestKey testKey = (TestKey)queue.Dequeue();
                    bTree.DeleteKey( testKey, (int)testKey.Key );
                    numbers.Remove( (int)testKey.Key );
                    TestKey newKey = new TestKey( GetUniqueRand( numbers ) );
                    queue.Enqueue( newKey );
                    bTree.InsertKey( newKey, (int)newKey.Key );
                }
                time = System.Environment.TickCount - time;
                Console.WriteLine( " work took " + time.ToString() );

                bTree.Close();
            }
        }
Example #2
0
        public void BatchSearchingBackward()
        {
            TestKey keyFactory = new TestKey();
            IBTree bTree = new /*BTree*/OmniaMeaBTree( _indexFileName, keyFactory );
            using( bTree )
            {
                bTree.Open();
                IntArrayList offsets = new IntArrayList();
                for( int i = 10000; i > 0; i-- )
                {
                    bTree.InsertKey( new TestKey( i ), i );
                    offsets.Clear();
                    bTree.SearchForRange( new TestKey( i ), new TestKey( i ), offsets );
                    Assert.AreEqual( true, FindOffset( offsets, i ), i.ToString() + " not found" );
                }
                Assert.AreEqual( 10000, bTree.Count );
                for( int i = 10000; i > 0; i-- )
                {
                    bTree.DeleteKey( new TestKey( i ), i );
                    offsets.Clear();
                    bTree.SearchForRange( new TestKey( i ), new TestKey( i ), offsets );
                    Assert.AreEqual( 0, offsets.Count, i.ToString() + " must not be found" );
                    Assert.AreEqual( false, FindOffset( offsets, i ) );
                }
                Assert.AreEqual( 0, bTree.Count );

                bTree.Close();
                bTree.Open();
                Assert.AreEqual( 0, bTree.Count );
                bTree.Close();
            }
        }
Example #3
0
 public void BatchInsertingAndReopen()
 {
     TestKey keyFactory = new TestKey();
     IBTree bTree = new /*BTree*/OmniaMeaBTree( _indexFileName, keyFactory );
     using( bTree )
     {
         bTree.Open();
         for( int i = 0; i < 10000; i++ )
         {
             bTree.InsertKey( new TestKey( i ), i );
         }
         Assert.AreEqual( 10000, bTree.Count );
         bTree.Close();
         bTree.Open();
         Assert.AreEqual( 10000, bTree.Count );
         for( int i = 10000; i < 20000; i++ )
         {
             bTree.InsertKey( new TestKey( i ), i );
         }
         Assert.AreEqual( 20000, bTree.Count );
         bTree.Close();
         bTree.Open();
         Assert.AreEqual( 20000, bTree.Count );
         bTree.Close();
     }
 }
Example #4
0
 public void GroupsMultipleEqualKeys()
 {
     const int cycles = 20000;
     TestKey keyFactory = new TestKey( 0 );
     IBTree bTree = new /*BTree*/OmniaMeaBTree( _indexFileName, keyFactory );
     using( bTree )
     {
         bTree.Open();
         for( int j = 0; j < 10; ++j )
         {
             for( int i = 0; i < cycles; ++i )
             {
                 bTree.InsertKey( new TestKey( j ), i );
             }
         }
         for( int j = 0; j < 10; ++j )
         {
             IntArrayList offsets = new IntArrayList();
             bTree.SearchForRange( new TestKey( j ), new TestKey( j ), offsets );
             Assert.AreEqual( cycles, offsets.Count );
             for( int i = 0; i < cycles; ++i )
             {
                 bTree.DeleteKey( new TestKey( j ), i );
             }
         }
         bTree.Close();
     }
 }
Example #5
0
 public void Clearing()
 {
     TestKey keyFactory = new TestKey();
     IBTree bTree = new /*BTree*/OmniaMeaBTree( _indexFileName, keyFactory );
     using( bTree )
     {
         bTree.Open();
         bTree.InsertKey( new TestKey( 1 ), 1 );
         for( int i = 0; i < 10000; i++ )
         {
             bTree.InsertKey( new TestKey( 2 ), i );
         }
         bTree.InsertKey( new TestKey( 3 ), 3 );
         IntArrayList offsets = new IntArrayList();
         bTree.SearchForRange( new TestKey( 2 ), new TestKey( 2 ), offsets );
         Assert.AreEqual( 10000, offsets.Count );
         bTree.Clear();
         offsets.Clear();
         bTree.SearchForRange( new TestKey( 2 ), new TestKey( 2 ), offsets );
         Assert.AreEqual( 0, offsets.Count );
         Assert.AreEqual( 0, bTree.Count );
         for( int i = 0; i < 10000; i++ )
         {
             bTree.InsertKey( new TestKey( 2 ), i );
         }
         Assert.AreEqual( 10000, bTree.Count );
         bTree.Close();
     }
 }
Example #6
0
        public void RangeSearching3()
        {
            TestKey keyFactory = new TestKey();
            IBTree  bTree      = new /*BTree*/ OmniaMeaBTree(_indexFileName, keyFactory);

            bTree.SetCacheSize(2);
            bTree.Open();
            for (int i = 0; i < 100000; i++)
            {
                bTree.InsertKey(new TestKey(2), i);
            }
            IntArrayList offsets = new IntArrayList();

            bTree.SearchForRange(new TestKey(2), new TestKey(2), offsets);

            Assert.AreEqual(true, FindOffset(offsets, 9000));
            bTree.DeleteKey(new TestKey(2), 9000);

            offsets.Clear();
            bTree.SearchForRange(new TestKey(2), new TestKey(2), offsets);
            Assert.AreEqual(false, FindOffset(offsets, 9000));

            Assert.AreEqual(true, FindOffset(offsets, 1));
            bTree.DeleteKey(new TestKey(2), 1);
            offsets.Clear();
            bTree.SearchForRange(new TestKey(2), new TestKey(2), offsets);
            Assert.AreEqual(false, FindOffset(offsets, 1));

            bTree.Close();
        }
Example #7
0
        public void BatchSearching()
        {
            TestKey keyFactory = new TestKey();
            IBTree  bTree      = new /*BTree*/ OmniaMeaBTree(_indexFileName, keyFactory);

            bTree.SetCacheSize(2);
            bTree.Open();
            for (int i = 0; i < 10000; i++)
            {
                bTree.InsertKey(new TestKey(i), i);
            }
            Assert.AreEqual(10000, bTree.Count);
            IntArrayList offsets = new IntArrayList();

            for (int i = 0; i < 10000; i++)
            {
                bTree.DeleteKey(new TestKey(i), i);
                offsets.Clear();
                bTree.SearchForRange(new TestKey(i), new TestKey(Int32.MaxValue), offsets);
                Assert.AreEqual(10000 - i - 1, offsets.Count);
                Assert.AreEqual(false, FindOffset(offsets, i));
            }
            Assert.AreEqual(0, bTree.Count);

            bTree.Close();
            bTree.Open();
            Assert.AreEqual(0, bTree.Count);
            bTree.Close();
        }
Example #8
0
        public void SearchForRangeOrderTest()
        {
            IntHashSet numbers = new IntHashSet();
            TestKey keyFactory = new TestKey();
            IBTree bTree = new /*BTree*/OmniaMeaBTree( _indexFileName, keyFactory );
            using( bTree )
            {
                bTree.Open();
                TestKey testKey = new TestKey( 0 );

                for ( int i = 0; i < 10000; i++ )
                {
                    testKey = new TestKey( GetUniqueRand( numbers ) );
                    bTree.InsertKey( testKey, (int)testKey.Key );
                }

                ArrayList keys_offsets = new ArrayList();
                bTree.SearchForRange( new TestKey( 0 ), testKey, keys_offsets );
                for( int j = 1; j < keys_offsets.Count; ++j )
                {
                    KeyPair pair1 = (KeyPair) keys_offsets[ j - 1 ];
                    KeyPair pair2 = (KeyPair) keys_offsets[ j ];
                    if( pair1._key.CompareTo( pair2._key ) > 0 )
                    {
                        throw new Exception( "Invalid key order, j = " + j );
                    }
                }

                bTree.Close();
            }
        }
Example #9
0
        public void SequentialSearchDeleteInsert()
        {
            IntHashSet numbers = new IntHashSet();
            const int queueSize = 100000;
            TestKey keyFactory = new TestKey();
            IBTree bTree = new /*BTree*/OmniaMeaBTree( _indexFileName, keyFactory );
            using( bTree )
            {
                bTree.Open( );

                //Random random = new Random( System.Environment.TickCount );
                Queue queue = new Queue( queueSize );
                for ( int i = 0; i < queueSize; i++ )
                {
                    int key = GetUniqueRand( numbers );
                    TestKey testKey = new TestKey( key );
                    queue.Enqueue( testKey );
                    bTree.InsertKey( testKey, key );
                }
                bTree.Close();
                if( !bTree.Open() )
                {
                    throw new Exception( "Can't reopen btree! ");
                }
                int time = System.Environment.TickCount;
                IntArrayList offsets = new IntArrayList();
                for ( int i = 0; i < 20000; i++ )
                {
                    TestKey testKey = (TestKey)queue.Dequeue();
                    offsets.Clear();
                    bTree.SearchForRange( testKey, testKey, offsets );
                    Assert.AreEqual( 1, offsets.Count, testKey.Key.ToString() + " not found. i = " + i.ToString() );
                    Assert.AreEqual( (int)testKey.Key, offsets[0] );
                    bTree.DeleteKey( testKey, (int)testKey.Key );
                    numbers.Remove( (int)testKey.Key );
                    offsets.Clear();
                    bTree.SearchForRange( testKey, testKey, offsets );
                    Assert.AreEqual( 0, offsets.Count );
                    TestKey newKey = new TestKey( GetUniqueRand( numbers ) );
                    queue.Enqueue( newKey );
                    bTree.InsertKey( newKey, (int)newKey.Key );
                    offsets.Clear();
                    bTree.SearchForRange( newKey, newKey, offsets );
                    Assert.AreEqual( 1, offsets.Count );
                    Assert.AreEqual( (int)newKey.Key, offsets[0] );
                }
                time = System.Environment.TickCount - time;
                Console.WriteLine( " work took " + time.ToString() );

                bTree.Close();
            }
        }
Example #10
0
        public void BatchInsertingAndDeleting()
        {
            TestKey keyFactory = new TestKey();
            IBTree bTree = new /*BTree*/OmniaMeaBTree( _indexFileName, keyFactory );
            using( bTree )
            {
                bTree.Open();
                for( int i = 0; i < 10000; i++ )
                {
                    bTree.InsertKey( new TestKey( i ), i );
                }
                Assert.AreEqual( 10000, bTree.Count );
                for( int i = 0; i < 10000; i++ )
                {
                    bTree.DeleteKey( new TestKey( i ), i );
                }
                Assert.AreEqual( 0, bTree.Count );

                bTree.Close();
                bTree.Open();
                Assert.AreEqual( 0, bTree.Count );
                for( int i = 0; i < 10; i++ )
                {
                    bTree.InsertKey( new TestKey( i ), i );
                }
                Assert.AreEqual( 10, bTree.Count );
                IntArrayList offsets = new IntArrayList();
                for( int i = 0; i < 10; i++ )
                {
                    offsets.Clear();
                    bTree.SearchForRange( new TestKey( i ), new TestKey( i ), offsets );
                    Assert.AreEqual( 1, offsets.Count );
                    Assert.AreEqual( i, offsets[0] );
                }
                for( int i = 0; i < 10; i++ )
                {
                    bTree.DeleteKey( new TestKey( i ), i );
                }
                Assert.AreEqual( 0, bTree.Count );
                for( int i = 0; i < 10; i++ )
                {
                    offsets.Clear();
                    bTree.SearchForRange( new TestKey( i ), new TestKey( i ), offsets );
                    Assert.AreEqual( 0, offsets.Count );
                }
                bTree.Close();
            }
        }
Example #11
0
 public void MultiThreadedStress()
 {
     AsyncProcessor processor1 = new AsyncProcessor();
     AsyncProcessor processor2 = new AsyncProcessor();
     IBTree bTree1 = new /*BTree*/OmniaMeaBTree( _indexFileName, new TestKey( 0 ) );
     IBTree bTree2 = new /*BTree*/OmniaMeaBTree( _indexFileName + "2", new TestKey( 0 ) );
     processor1.QueueJob( new DoStressProcessingDelegate( DoStressProcessing ), bTree1 );
     processor2.QueueJob( new DoStressProcessingDelegate( DoStressProcessing ), bTree2 );
     using( processor1 )
     {
         using( processor2 )
         {
             Thread.Sleep( 1000 );
         }
     }
 }
Example #12
0
 public void GetAllOffsets()
 {
     TestKey keyFactory = new TestKey();
     IBTree bTree = new /*BTree*/OmniaMeaBTree( _indexFileName, keyFactory );
     using( bTree )
     {
         bTree.Open();
         bTree.InsertKey( new TestKey( 1 ), 1 );
         for( int i = 0; i < 10000; i++ )
         {
             bTree.InsertKey( new TestKey( 2 ), i );
         }
         bTree.InsertKey( new TestKey( 3 ), 3 );
         IntArrayList offsets = new IntArrayList();
         bTree.GetAllKeys( offsets );
         Assert.AreEqual( 10002, offsets.Count );
         bTree.Close();
         bTree.Open();
         offsets.Clear();
         bTree.GetAllKeys( offsets );
         Assert.AreEqual( 10002, offsets.Count );
         for( int i = 5; i < 15; ++i )
         {
             bTree.InsertKey( new TestKey( i - 5 ), i );
         }
         bTree.Close();
         bTree.Open();
         offsets.Clear();
         bTree.GetAllKeys( offsets );
         Assert.AreEqual( 10012, offsets.Count );
         bTree.Close();
         bTree.Open();
         for( int i = 5; i < 15; ++i )
         {
             bTree.DeleteKey( new TestKey( i - 5 ), i );
         }
         offsets.Clear();
         bTree.GetAllKeys( offsets );
         Assert.AreEqual( 10002, offsets.Count );
         bTree.Close();
         bTree.Open();
         offsets.Clear();
         bTree.GetAllKeys( offsets );
         Assert.AreEqual( 10002, offsets.Count );
         bTree.Close();
     }
 }
Example #13
0
 public void MultipleEqualKeys()
 {
     const int cycles = 10000;
     TestKey keyFactory = new TestKey( 0 );
     IBTree bTree = new /*BTree*/OmniaMeaBTree( _indexFileName, keyFactory );
     using( bTree )
     {
         bTree.Open();
         for( int i = 0; i < cycles; ++i )
         {
             bTree.InsertKey( keyFactory, i );
         }
         IntArrayList offsets = new IntArrayList();
         bTree.SearchForRange( keyFactory, keyFactory, offsets );
         Assert.AreEqual( cycles, bTree.Count );
         Assert.AreEqual( cycles, offsets.Count );
         bTree.Close();
     }
 }
Example #14
0
        public void Deleting()
        {
            TestKey keyFactory = new TestKey();
            IBTree bTree = new /*BTree*/OmniaMeaBTree( _indexFileName, keyFactory );
            using( bTree )
            {
                bTree.Open();
                bTree.InsertKey( new TestKey( 1 ), 1 );
                bTree.InsertKey( new TestKey( 2 ), 2 );
                Assert.AreEqual( 2, bTree.Count );
                bTree.DeleteKey( new TestKey( 2 ), 2 );
                Assert.AreEqual( 1, bTree.Count );
                IntArrayList offsets = new IntArrayList();
                bTree.SearchForRange( new TestKey( 1 ), new TestKey( 1 ), offsets );
                Assert.AreEqual( 1, offsets.Count );
                Assert.AreEqual( 1, offsets[0] );

                bTree.Close();
            }
        }
Example #15
0
 public void SmallCacheBTreeReopen()
 {
     TestKey keyFactory = new TestKey( 0 );
     IBTree bTree = new /*BTree*/OmniaMeaBTree( _indexFileName, keyFactory );
     using( bTree )
     {
         bTree.SetCacheSize(  2 );
         bTree.Open();
         for( int i = 0; i < 50000; ++i )
         {
             bTree.InsertKey( new TestKey( i ), i );
         }
         bTree.Close();
         bTree.Open();
         for( int i = 0; i < 15000; ++i )
         {
             IntArrayList offsets = new IntArrayList();
             bTree.SearchForRange( new TestKey( i ), new TestKey( i ), offsets );
             Assert.AreEqual( 1, offsets.Count );
             bTree.DeleteKey( new TestKey( i ), i );
         }
         bTree.Close();
         bTree.Open();
         for( int i = 15000; i < 30000; ++i )
         {
             IntArrayList offsets = new IntArrayList();
             bTree.SearchForRange( new TestKey( i ), new TestKey( i ), offsets );
             Assert.AreEqual( 1, offsets.Count );
             bTree.DeleteKey( new TestKey( i ), i );
         }
         bTree.Close();
         bTree.Open();
         for( int i = 30000; i < 50000; ++i )
         {
             IntArrayList offsets = new IntArrayList();
             bTree.SearchForRange( new TestKey( i ), new TestKey( i ), offsets );
             Assert.AreEqual( 1, offsets.Count );
         }
         bTree.Close();
     }
 }
Example #16
0
        public void SuccessiveClosingOpeningTest()
        {
            TestKey keyFactory = new TestKey();
            IBTree  bTree      = new /*BTree*/ OmniaMeaBTree(_indexFileName, keyFactory);

            bTree.SetCacheSize(16);
            bTree.Open();
            const int bTreeSize = 200003; // !!!!! PRIME NUMBER !!!!!

            for (int i = 0; i < bTreeSize; ++i)
            {
                bTree.InsertKey(new TestKey(i), i);
            }
            Random rnd    = new Random();
            int    insert = rnd.Next(bTreeSize) + bTreeSize;
            int    delete = rnd.Next(bTreeSize);

            for (int i = 0; i < 1000; ++i)
            {
                bTree.Close();
                bTree.Open();
                if (bTreeSize != bTree.Count)
                {
                    throw new Exception("After Open() bTreeSize != bTree.Count, i = " + i);
                }
                for (int j = 0; j < 50; ++j)
                {
                    bTree.InsertKey(new TestKey(insert), insert);
                    bTree.DeleteKey(new TestKey(delete), delete);
                    insert = (insert + 50000) % bTreeSize + bTreeSize;
                    delete = (delete + 50000) % bTreeSize;
                }
                if (bTreeSize != bTree.Count)
                {
                    throw new Exception("After inserting/deleting bTreeSize != bTree.Count, i = " + i);
                }
            }
            bTree.Close();
        }
Example #17
0
        public void SequentialInsertAndDelete()
        {
            IntHashSet numbers = new IntHashSet();
            const int queueSize = 10000;
            TestKey keyFactory = new TestKey();
            IBTree bTree = new /*BTree*/OmniaMeaBTree( _indexFileName, keyFactory );
            using( bTree )
            {
                bTree.Open();
                int time = System.Environment.TickCount;
                Queue queue = new Queue( queueSize );
                const int cycles = 2;

                for( int count = 0; count < cycles; ++count )
                {
                    for ( int i = 0; i < queueSize; i++ )
                    {
                        TestKey testKey = new TestKey( GetUniqueRand( numbers ) );
                        queue.Enqueue( testKey );
                        bTree.InsertKey( testKey, (int)testKey.Key );
                    }
                    for ( int i = 0; i < queueSize - 1; i++ )
                    {
                        TestKey testKey = (TestKey)queue.Dequeue();
                        bTree.DeleteKey( testKey, (int)testKey.Key );
                        numbers.Remove( (int)testKey.Key );
                    }
                    queue.Clear();
                }

                Assert.AreEqual( cycles, bTree.Count );

                time = System.Environment.TickCount - time;
                Console.WriteLine( " work took " + time.ToString() );

                bTree.Close();
            }
        }
Example #18
0
        public void TestRBInsideBTree()
        {
            int test     = 0;
            int maxCount = 1; //40
            int attempts = 2; //7

            while (true)
            {
                test++;
                TestKey keyFactory = new TestKey();
                IBTree  bTree      = new /*BTree*/ OmniaMeaBTree(test.ToString() + ".btree_test", keyFactory);
                bTree.SetCacheSize(2);

                IntArrayList offsets = new IntArrayList();
                maxCount++;
                if (maxCount > 40)
                {
                    maxCount = 1;
                    attempts++;
                }
                if (attempts > 3)
                {
                    break;
                }
                Console.WriteLine("Attempts = " + attempts.ToString() + " maxCount = " + maxCount.ToString());
                for (int j = 0; j < attempts; j++)
                {
                    bTree.Open();
                    for (int i = 0; i < maxCount; i++)
                    {
                        bTree.InsertKey(new TestKey(i), i);
                        offsets.Clear();
                        bTree.SearchForRange(new TestKey(i), new TestKey(i), offsets);
                        Assert.AreEqual(1, offsets.Count);
                        Assert.AreEqual(i, offsets[0]);
                        offsets.Clear();
                        bTree.SearchForRange(new TestKey(0), new TestKey(maxCount), offsets);
                        Assert.AreEqual(i + 1, offsets.Count);
                        int expectedOffset = 0;
                        foreach (int offset in offsets)
                        {
                            Assert.AreEqual(expectedOffset, offset);
                            expectedOffset++;
                        }
                    }
                    for (int i = 0; i < maxCount; i++)
                    {
                        bTree.DeleteKey(new TestKey(i), i);
                        offsets.Clear();
                        bTree.SearchForRange(new TestKey(i), new TestKey(i), offsets);
                        Assert.AreEqual(0, offsets.Count);
                        offsets.Clear();
                        bTree.SearchForRange(new TestKey(0), new TestKey(maxCount), offsets);
                        Assert.AreEqual(maxCount - i - 1, offsets.Count);
                        int expectedOffset = 0;
                        foreach (int offset in offsets)
                        {
                            Assert.AreEqual(expectedOffset + i + 1, offset);
                            expectedOffset++;
                        }
                    }
                    for (int i = maxCount; i > 0; i--)
                    {
                        bTree.InsertKey(new TestKey(i), i);
                        offsets.Clear();
                        bTree.SearchForRange(new TestKey(i), new TestKey(i), offsets);
                        Assert.AreEqual(1, offsets.Count);
                        Assert.AreEqual(i, offsets[0]);
                        offsets.Clear();
                        bTree.SearchForRange(new TestKey(0), new TestKey(maxCount), offsets);
                        Assert.AreEqual(maxCount - i + 1, offsets.Count);
                        int expectedOffset = i;
                        foreach (int offset in offsets)
                        {
                            Assert.AreEqual(expectedOffset, offset);
                            expectedOffset++;
                        }
                    }
                    for (int i = maxCount; i > 0; i--)
                    {
                        bTree.DeleteKey(new TestKey(i), i);
                        offsets.Clear();
                        bTree.SearchForRange(new TestKey(i), new TestKey(i), offsets);
                        Assert.AreEqual(0, offsets.Count);
                        offsets.Clear();
                        bTree.SearchForRange(new TestKey(0), new TestKey(maxCount), offsets);
                        Assert.AreEqual(i - 1, offsets.Count);
                        int expectedOffset = 0;
                        foreach (int offset in offsets)
                        {
                            Assert.AreEqual(expectedOffset + 1, offset);
                            expectedOffset++;
                        }
                    }
                    bTree.Close();
                }
            }
        }
Example #19
0
 public void SingleThreadedStress()
 {
     IBTree bTree = new /*BTree*/OmniaMeaBTree( _indexFileName, new TestKey( 0 ) );
     DoStressProcessing( bTree );
 }
Example #20
0
        public void EmulateSequentialSplit_ThenDeleteAndGetAllKeys()
        {
            TestKey keyFactory = new TestKey();
            TestKey testKey;
            IBTree bTree = new /*BTree*/OmniaMeaBTree( _indexFileName, keyFactory );
            using( bTree )
            {
                bTree.Open();
                for( int i = 0; i < 10; ++i )
                {
                    testKey = new TestKey( 0 );
                    bTree.InsertKey( testKey, i );
                }
                for( int i = 0; i < 10; ++i )
                {
                    testKey = new TestKey( Int32.MaxValue );
                    bTree.InsertKey( testKey, i );
                }
                for( int i = 1; i < 4991; ++i )
                {
                    testKey = new TestKey( i );
                    bTree.InsertKey( testKey, 0 );
                    testKey = new TestKey( Int32.MaxValue - i );
                    bTree.InsertKey( testKey, 0 );
                }
                int count_ = bTree.Count;
                Assert.AreEqual( 10000, count_ );
                bTree.Close();
                bTree.Open();
                ArrayList keys = new ArrayList( count_ );
                bTree.GetAllKeys( keys );
                if( keys.Count != count_ || bTree.Count != count_ )
                {
                    throw new Exception(
                        "keys.Count = " +  keys.Count + ", bTree.Count = " + bTree.Count + ", count_ = " + count_ );
                }
                testKey = new TestKey( 0 );
                bTree.DeleteKey( testKey, 0 );
                bTree.DeleteKey( testKey, 1 );
                bTree.DeleteKey( testKey, 2 );
                testKey = new TestKey( Int32.MaxValue );
                bTree.DeleteKey( testKey, 9 );
                bTree.DeleteKey( testKey, 8 );
                bTree.DeleteKey( testKey, 7 );
                for( int i = 10000; i < 55003; ++i )
                {
                    testKey = new TestKey( i );
                    bTree.InsertKey( testKey, 0 );
                    testKey = new TestKey( Int32.MaxValue - i );
                    bTree.InsertKey( testKey, 0 );
                }
                count_ = bTree.Count;
                Assert.AreEqual( 100000, count_ );
                bTree.Close();
                bTree.Open();
                keys = new ArrayList( count_ );
                bTree.GetAllKeys( keys );
                if( keys.Count != count_ || bTree.Count != count_ )
                {
                    throw new Exception(
                        "keys.Count = " +  keys.Count + ", bTree.Count = " + bTree.Count + ", count_ = " + count_ );
                }

                bTree.Close();
            }
        }
Example #21
0
        public void SequentialInsertDeleteGetAllKeys()
        {
            IntHashSet numbers = new IntHashSet();
            const int queueSize = 3000;
            const int cacheSize = 32;
            TestKey keyFactory = new TestKey();
            IBTree bTree = new /*BTree*/OmniaMeaBTree( _indexFileName, keyFactory );
            bTree.SetCacheSize( cacheSize );
            using( bTree )
            {
                bTree.Open();
                int time = System.Environment.TickCount;
                Queue queue = new Queue( queueSize );
                const int cycles = 20;

                for ( int i = 0; i < queueSize * cacheSize; i++ )
                {
                    TestKey testKey = new TestKey( GetUniqueRand( numbers ) );
                    bTree.InsertKey( testKey, (int)testKey.Key );
                }

                for( int count = 0; count < cycles; ++count )
                {
                    for ( int i = 0; i < queueSize; i++ )
                    {
                        TestKey testKey = new TestKey( GetUniqueRand( numbers ) );
                        queue.Enqueue( testKey );
                        bTree.InsertKey( testKey, (int)testKey.Key );
                    }
                    int count_ = bTree.Count;
                    bTree.Close();
                    bTree.Open();
                    ArrayList keys = new ArrayList( count_ );
                    IntArrayList ints = new IntArrayList( count_ );
                    bTree.GetAllKeys( keys );
                    if( keys.Count != count_ || bTree.Count != count_ )
                    {
                        throw new Exception(
                            "keys.Count = " +  keys.Count + ", bTree.Count = " + bTree.Count + ", count_ = " + count_ );
                    }
                    foreach( KeyPair pair in keys )
                    {
                        ints.Add( (int) pair._key.Key );
                    }
                    for ( int i = 0; i < queueSize - 1; i++ )
                    {
                        TestKey testKey = (TestKey)queue.Dequeue();
                        int key = (int)testKey.Key;
                        bTree.DeleteKey( testKey, key );
                        numbers.Remove( key );
                        if( ints.BinarySearch( key ) < 0 )
                        {
                            throw new Exception( "The ints array doesn't contain removed key" );
                        }
                    }
                    queue.Clear();
                }

                Assert.AreEqual( cycles + queueSize * cacheSize, bTree.Count );

                time = System.Environment.TickCount - time;
                Console.WriteLine( " work took " + time.ToString() );

                bTree.Close();
            }
        }