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(); } }
public void TestID(int id) { if (_ids != null) { _ids.Remove(id); } }
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(); } }
private void DoStressProcessing( IBTree bTree ) { const int initialSize = 500000; const int iterations = 1000000; IntHashSet uniqueKeys = new IntHashSet(); IntArrayList array = new IntArrayList(); using( bTree ) { bTree.Open(); for( int i = 0; i < initialSize; ++i ) { bTree.InsertKey( new TestKey( GetUniqueRand( uniqueKeys ) ), 0 ); } for( int i = 0; i < iterations; ++i ) { int key = 0; foreach( IntHashSet.Entry e in uniqueKeys ) { key = e.Key; break; } array.Clear(); bTree.SearchForRange( new TestKey( key ), new TestKey( key ), array ); Assert.AreEqual( 1, array.Count ); bTree.DeleteKey( new TestKey( key ), 0 ); uniqueKeys.Remove( key ); if( ( i & 31 ) == 5 ) { array.Clear(); bTree.GetAllKeys( array ); Assert.AreEqual( initialSize + i - 1, array.Count ); Assert.AreEqual( uniqueKeys.Count, array.Count ); } bTree.InsertKey( new TestKey( GetUniqueRand( uniqueKeys ) ), 0 ); bTree.InsertKey( new TestKey( GetUniqueRand( uniqueKeys ) ), 0 ); if( ( i & 31 ) == 17 ) { array.Clear(); bTree.GetAllKeys( array ); Assert.AreEqual( initialSize + i + 1, array.Count ); Assert.AreEqual( uniqueKeys.Count, array.Count ); } Trace.WriteLine( "Passes: " + i ); } bTree.Close(); } }
static public int Remove(IntPtr l) { try { IntHashSet self = (IntHashSet)checkSelf(l); System.Int32 a1; checkType(l, 2, out a1); var ret = self.Remove(a1); pushValue(l, true); pushValue(l, ret); return(2); } catch (Exception e) { return(error(l, e)); } }
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(); } }
private int GetNextDocId() { int docId = -1; _pendingDocsLock.Enter(); try { foreach (IntHashSet.Entry e in _pendingDocs) { docId = e.Key; break; } if (docId >= 0) { _pendingDocs.Remove(docId); } } finally { _pendingDocsLock.Exit(); } return(docId); }
public void StartImport() { if (_watcher != null) { _watcher.Changed -= new FileSystemEventHandler(AsyncUpdateBookmarks); _watcher.Dispose(); _watcher = null; } _root = _bookmarkservice.GetProfileRoot(this); if (!_root.IsDeleted) { if (!ImportAllowed) { _root.SetProp(FavoritesPlugin._propInvisible, true); } else { _root.DeleteProp(FavoritesPlugin._propInvisible); IntHashSet nodes = new IntHashSet(); CollectAllSubNodes(_root, nodes); string path = OperaBookmarksPath(); if (path.Length > 0) { using (StreamReader reader = new StreamReader(path)) { IResource parent = _root; Stack parents = new Stack(); bool readingFolder = false; string id = string.Empty; string name = string.Empty; string url = string.Empty; string line; while ((line = reader.ReadLine()) != null) { line = line.Trim(' ', '\r', '\n', '\t'); if (Utils.StartsWith(line, "id=", true)) { id = line.Substring(3); continue; } if (Utils.StartsWith(line, "name=", true)) { name = line.Substring(5); continue; } if (Utils.StartsWith(line, "url=", true)) { url = line.Substring(4); IResource bookmark = _bookmarkservice.FindOrCreateBookmark(parent, name, url); bookmark.SetProp(FavoritesPlugin._propBookmarkId, id); nodes.Remove(bookmark.Id); } if (Utils.StartsWith(line, "#folder", true)) { if (readingFolder) { parent = _bookmarkservice.FindOrCreateFolder(parent, name); parent.SetProp(FavoritesPlugin._propBookmarkId, id); nodes.Remove(parent.Id); } parents.Push(parent); readingFolder = true; continue; } if (Utils.StartsWith(line, "#url", true)) { if (readingFolder) { parent = _bookmarkservice.FindOrCreateFolder(parent, name); parent.SetProp(FavoritesPlugin._propBookmarkId, id); nodes.Remove(parent.Id); } readingFolder = false; continue; } if (line == "-") { if (readingFolder) { parent = _bookmarkservice.FindOrCreateFolder(parent, name); parent.SetProp(FavoritesPlugin._propBookmarkId, id); nodes.Remove(parent.Id); } readingFolder = false; if (parents.Count == 0) { break; } parent = (IResource)parents.Pop(); } } } foreach (IntHashSet.Entry e in nodes) { Core.ResourceStore.LoadResource(e.Key).Delete(); } if (ImportImmediately) { _watcher = new FileSystemWatcher(); try { _watcher.Path = IOTools.GetDirectoryName(IOTools.GetFileInfo(path)); _watcher.Filter = "*.*"; _watcher.IncludeSubdirectories = false; _watcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName; _watcher.Changed += new FileSystemEventHandler(AsyncUpdateBookmarks); _watcher.EnableRaisingEvents = true; } catch { _watcher = null; } } } } } }
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(); } }