Exemple #1
0
        public void GetAllKeysEnumerator()
        {
            TestKey keyFactory = new TestKey( 0 );
            OmniaMeaBTree bTree = new OmniaMeaBTree( _indexFileName, keyFactory );
            using( bTree )
            {
                bTree.Open();
                for( int i = 0; i < 100000; ++i )
                {
                    bTree.InsertKey( new TestKey( i ), i );
                }
                int count = 0;
                foreach( KeyPair pair in bTree.GetAllKeys() )
                {
                    Assert.AreEqual( count, (int) pair._key.Key );
                    Assert.AreEqual( count, pair._offset );
                    ++count;
                }
                Assert.AreEqual( count, 100000 );

                KeyPair pair1 = bTree.GetMaximum();
                Assert.AreEqual( (int)pair1._key.Key, 99999 );
                pair1 = bTree.GetMinimum();
                Assert.AreEqual( (int)pair1._key.Key, 0 );

                // delete each 15 of 16 keys
                for( int i = 0; i < 100000; ++i )
                {
                    if( ( i & 15 ) != 0 )
                    {
                        bTree.DeleteKey( new TestKey( i ), i );
                    }
                }
                count = 0;
                foreach( KeyPair pair in bTree.GetAllKeys() )
                {
                    Assert.AreEqual( 16 * count, (int) pair._key.Key );
                    Assert.AreEqual( 16 * count, pair._offset );
                    ++count;
                }
                Assert.AreEqual( count, 100000 / 16 );
                pair1 = bTree.GetMaximum();
                Assert.AreEqual( (int)pair1._key.Key, 99984 );
                pair1 = bTree.GetMinimum();
                Assert.AreEqual( (int)pair1._key.Key, 0 );

                bTree.Close();
            }
        }
Exemple #2
0
        public void MultipleBTrees()
        {
            ArrayList keys = new ArrayList();
            TestKey keyFactory = new TestKey();
            TestKey sameKey = new TestKey( -1 );
            OmniaMeaBTree bTree1 = new OmniaMeaBTree( _indexFileName, keyFactory );
            OmniaMeaBTree bTree2 = new OmniaMeaBTree( _indexFileName + "2", keyFactory );
            OmniaMeaBTree bTree3 = new OmniaMeaBTree( _indexFileName + "3", keyFactory );
            bTree1.Open();
            bTree2.Open();
            bTree3.Open();
            for( int i = 0; i < 50000; i++ )
            {
                bTree1.InsertKey( new TestKey( i ), i + 1 );
                bTree2.InsertKey( new TestKey( i ), i + 1 );
                bTree3.InsertKey( new TestKey( i ), i + 1 );
            }

            bTree1.Close();
            bTree2.Close();
            bTree1.Open();
            bTree3.Close();
            bTree2.Open();
            bTree3.Open();

            Assert.AreEqual( 50000, bTree1.Count );
            Assert.AreEqual( 50000, bTree2.Count );
            Assert.AreEqual( 50000, bTree3.Count );

            keys.Clear();
            bTree1.GetAllKeys( keys );
            Assert.AreEqual( 50000, keys.Count );
            keys.Clear();
            bTree2.GetAllKeys( keys );
            Assert.AreEqual( 50000, keys.Count );
            keys.Clear();
            bTree3.GetAllKeys( keys );
            Assert.AreEqual( 50000, keys.Count );

            for( int i = 0; i < 50000; i++ )
            {
                bTree1.InsertKey( new TestKey( i ), i - 1 );
                bTree2.InsertKey( new TestKey( i ), i - 1 );
                bTree3.InsertKey( new TestKey( i ), i - 1 );
            }

            bTree1.Close();
            bTree2.Close();
            bTree3.Close();
            bTree3.Open();
            bTree2.Open();
            bTree1.Open();

            Assert.AreEqual( 100000, bTree1.Count );
            Assert.AreEqual( 100000, bTree2.Count );
            Assert.AreEqual( 100000, bTree3.Count );

            keys.Clear();
            bTree1.GetAllKeys( keys );
            Assert.AreEqual( 100000, keys.Count );
            keys.Clear();
            bTree2.GetAllKeys( keys );
            Assert.AreEqual( 100000, keys.Count );
            keys.Clear();
            bTree3.GetAllKeys( keys );
            Assert.AreEqual( 100000, keys.Count );

            for( int i = 50000; i > 0; i-- )
            {
                bTree1.InsertKey( new TestKey( i ), i + 2 );
                bTree2.InsertKey( new TestKey( i ), i + 2 );
                bTree3.InsertKey( new TestKey( i ), i + 2 );
            }

            bTree1.Close();
            bTree2.Close();
            bTree3.Close();
            bTree3.Open();
            bTree2.Open();
            bTree1.Open();

            Assert.AreEqual( 150000, bTree1.Count );
            Assert.AreEqual( 150000, bTree2.Count );
            Assert.AreEqual( 150000, bTree3.Count );

            keys.Clear();
            bTree1.GetAllKeys( keys );
            Assert.AreEqual( 150000, keys.Count );
            keys.Clear();
            bTree2.GetAllKeys( keys );
            Assert.AreEqual( 150000, keys.Count );
            keys.Clear();
            bTree3.GetAllKeys( keys );
            Assert.AreEqual( 150000, keys.Count );

            for( int i = 0; i < 1100; i++ )
            {
                bTree1.InsertKey( sameKey, i );
                bTree2.InsertKey( sameKey, i );
                bTree3.InsertKey( sameKey, i );
            }

            keys.Clear();
            bTree1.GetAllKeys( keys );
            Assert.AreEqual( 151100, keys.Count );
            keys.Clear();
            bTree2.GetAllKeys( keys );
            Assert.AreEqual( 151100, keys.Count );
            keys.Clear();
            bTree3.GetAllKeys( keys );
            Assert.AreEqual( 151100, keys.Count );

            keys.Clear();
            bTree1.SearchForRange( sameKey, sameKey, keys );
            Assert.AreEqual( 1100, keys.Count );
            keys.Clear();
            bTree2.SearchForRange( sameKey, sameKey, keys );
            Assert.AreEqual( 1100, keys.Count );
            keys.Clear();
            bTree3.SearchForRange( sameKey, sameKey, keys );
            Assert.AreEqual( 1100, keys.Count );

            bTree1.Close();
            bTree3.Close();
            bTree3.Dispose();
            bTree1.Dispose();
            bTree2.Close();
            bTree1.Dispose();
        }