public override void Load() { base.Load(); InitializationStart(); TermId2RecordHandle = new OmniaMeaBTree(IndexHeaderFileName, new TermIndexKey(0)); TermId2RecordHandle.SetCacheSize(40); if (!File.Exists(IndexHeaderFileName)) { Trace.WriteLineIf(!FullTextIndexer._suppTrace, "-- TermIndexAccessor - Header file [" + IndexHeaderFileName + "] does not exist."); Trace.WriteLineIf(!FullTextIndexer._suppTrace, "-- TermIndexAccessor - loading indices directly from index"); TermId2RecordHandle.Open(); LoadOffsetsFromIndex(); } else { bool status = TermId2RecordHandle.Open(); if (status && TermId2RecordHandle.Count > 0) { Trace.WriteLineIf(!FullTextIndexer._suppTrace, "-- TermIndexAccessor - loaded indices from header subcomponent"); Trace.WriteLineIf(!FullTextIndexer._suppTrace, "-- TermIndexAccessor - Number of loaded offsets: [" + TermId2RecordHandle.Count + "]"); } else { Trace.WriteLineIf(!FullTextIndexer._suppTrace, "-- TermIndexAccessor - Header file [" + IndexHeaderFileName + "] exists"); Trace.WriteLineIf(!FullTextIndexer._suppTrace, !status ? " but did not open." : ", opened but its count is 0."); Trace.WriteLineIf(!FullTextIndexer._suppTrace, "-- TermIndexAccessor - loading indices directly from index"); TermId2RecordHandle.Clear(); LoadOffsetsFromIndex(); } } InitializationFinish(); }
public void SearchForRangeEnumerator() { TestKey keyFactory = new TestKey( 0 ); IBTree 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.SearchForRange( new TestKey( 0 ), new TestKey( 9999 ) ) ) { Assert.AreEqual( count, (int) pair._key.Key ); Assert.AreEqual( count, pair._offset ); ++count; } Assert.AreEqual( count, 10000 ); count = 0; foreach( KeyPair pair in bTree.SearchForRange( new TestKey( 100001 ), new TestKey( 100001 ) ) ) { Assert.AreEqual( count, (int) pair._key.Key ); Assert.AreEqual( count, pair._offset ); ++count; } Assert.AreEqual( count, 0 ); count = 0; foreach( KeyPair pair in bTree.SearchForRange( new TestKey( 49999 ), new TestKey( 49999 ) ) ) { Assert.AreEqual( (int) pair._key.Key, 49999 ); Assert.AreEqual( pair._offset, 49999 ); ++count; } Assert.AreEqual( count, 1 ); // 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.SearchForRange( new TestKey( 0 ), new TestKey( 100000 ) ) ) { Assert.AreEqual( 16 * count, (int) pair._key.Key ); Assert.AreEqual( 16 * count, pair._offset ); ++count; } Assert.AreEqual( count, 100000 / 16 ); bTree.Close(); } }
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(); } }
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(); }