Ejemplo n.º 1
0
        public void RemoveItem_InMemory()
        {
            int    ItemCount = 5000;
            string s         = string.Format("Collection{0}", 0);
            var    sortDict  = new Sop.Collections.Generic.SortedDictionary <int, int>();
            int    loopCount = 25;

            for (int i = 0; i < loopCount; i++)
            {
                for (int i2 = 0; i2 < ItemCount; i2++)
                {
                    sortDict.Add(i2, i2);
                }
                for (int i2 = 0; i2 < 500; i2++)
                {
                    sortDict.Remove(i2);
                }
            }

            //for (int i = 0; i < loopCount; i++)
            //{
            //    //for (int i2 = 0; i2 < ItemCount; i2++)
            //    //    Assert.AreEqual(i2, sortDict[i2]);
            //    for (int i2 = 0; i2 < 500; i2++)
            //        sortDict.Remove(i2);
            //}
            //sortDict.Dispose();
        }
Ejemplo n.º 2
0
        public void ReadBlockFromDisk(Algorithm.Collection.ICollectionOnDisk parent,
                                      List <Algorithm.BTree.BTreeItemOnDisk> items, System.Func <int, bool> readCallback)
        {
            var sortedBlocks = new Sop.Collections.Generic.SortedDictionary <long, int>();
            var dataSegments = new Sop.Collections.Generic.SortedDictionary <long, long>();

            for (int i = 0; i < items.Count; i++)
            {
                var address = GetId(items[i].Value.DiskBuffer);
                sortedBlocks.Add(address, i);
            }
            dataSegments.Clear();

            //detect contiguous blocks & read these data blocks as a bigger segment for optimal reading.
            KeyValuePair <long, int>         lastEntry;
            List <KeyValuePair <long, int> > blockAddresses = new List <KeyValuePair <long, int> >();

            foreach (var entry in sortedBlocks)
            {
                lastEntry = entry;
                var address = entry.Key;
                blockAddresses.Add(entry);
                if (!Algorithm.BTree.IndexedBlockRecycler.DetectAndMerge(dataSegments,
                                                                         address, items[entry.Value].Value.DiskBuffer.contiguousBlockCount * (int)parent.DataBlockSize, MaxSegmentSize))
                {
                    _readAheadBuffer.Clear();
                    dataSegments.MoveFirst();
                    _readAheadBuffer.Read(parent.FileStream, dataSegments.CurrentKey, (int)dataSegments.CurrentValue);

                    foreach (var addr in blockAddresses)
                    {
                        var rab   = new DataBlockReadBufferLogic(_readAheadBuffer);
                        var block = ReadBlockFromDisk(parent, addr.Key, false);
                        items[addr.Value].Value.DiskBuffer = block;
                        // process(deserialize the Object) the read blocks...
                        readCallback(addr.Value);
                        _readAheadBuffer = rab;
                    }
                    blockAddresses.Clear();
                    dataSegments.Clear();
                    dataSegments.Add(address, items[entry.Value].Value.DiskBuffer.contiguousBlockCount * (int)parent.DataBlockSize);
                }
            }
            // process last data segment...
            if (dataSegments.Count > 0)
            {
                _readAheadBuffer.Clear();
                dataSegments.MoveFirst();
                _readAheadBuffer.Read(parent.FileStream, dataSegments.CurrentKey, (int)dataSegments.CurrentValue);
                foreach (var addr in blockAddresses)
                {
                    var rab   = new DataBlockReadBufferLogic(_readAheadBuffer);
                    var block = ReadBlockFromDisk(parent, addr.Key, false);
                    items[addr.Value].Value.DiskBuffer = block;
                    // process(deserialize the Object) the read blocks...
                    readCallback(addr.Value);
                    _readAheadBuffer = rab;
                }
            }
        }