Exemple #1
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();
     }
 }
Exemple #2
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();
            }
        }
Exemple #3
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();
            }
        }