Esempio 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();
        }
Esempio 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;
                }
            }
        }
Esempio n. 3
0
        public void InMemoryTree_RemoveItemTest()
        {
            const int ItemCount = 1;
            var       SDODs     = new Sop.Collections.Generic.SortedDictionary <int, int> [ItemCount];

            for (int ii = 0; ii < 3; ii++)
            {
                var sortDict = SDODs[0];
                if (sortDict == null)
                {
                    sortDict = new Sop.Collections.Generic.SortedDictionary <int, int>();
                    SDODs[0] = sortDict;
                }
                for (int i2 = 0; i2 < 5000; i2++)
                {
                    sortDict.Add(i2, i2);
                }
                sortDict = SDODs[0];
                for (int i2 = 0; i2 < 500; i2++)
                {
                    sortDict.Remove(i2);
                }
            }
        }
Esempio n. 4
0
        public void RemoveUpdateItem_InMemoryTest()
        {
            const int ItemCount = 20;
            var       SDODs     = new Sop.Collections.Generic.SortedDictionary <int, int> [ItemCount];

            for (int ii = 0; ii < 3; ii++)
            {
                int StoreItemCount = 0;
                // add
                for (int i = 0; i < ItemCount; i++)
                {
                    var sortDict = SDODs[i];
                    if (sortDict == null)
                    {
                        sortDict = new Sop.Collections.Generic.SortedDictionary <int, int>();
                        SDODs[i] = sortDict;
                    }
                    if (StoreItemCount == 0)
                    {
                        StoreItemCount = sortDict.Count;
                    }
                    else if (sortDict.Count != StoreItemCount)
                    {
                        Assert.Fail(string.Format("sortDict.Count {0}, expected {1}", sortDict.Count, StoreItemCount));
                    }
                    for (int i2 = 0; i2 < 5000; i2++)
                    {
                        sortDict.Add(i2, i2 + i);
                    }
                }
                StoreItemCount = 0;
                // remove
                for (int i = 0; i < ItemCount; i++)
                {
                    var sortDict = SDODs[i];
                    if (StoreItemCount == 0)
                    {
                        StoreItemCount = sortDict.Count;
                    }
                    else if (sortDict.Count != StoreItemCount)
                    {
                        Assert.Fail(string.Format("sortDict.Count {0}, expected {1}", sortDict.Count, StoreItemCount));
                    }
                    for (int i2 = 0; i2 < 500; i2++)
                    {
                        sortDict.Remove(i2);
                    }
                }
                StoreItemCount = 0;
                // update
                for (int i = 0; i < ItemCount; i++)
                {
                    var sortDict = SDODs[i];
                    if (StoreItemCount == 0)
                    {
                        StoreItemCount = sortDict.Count;
                    }
                    else if (sortDict.Count != StoreItemCount)
                    {
                        Assert.Fail(string.Format("sortDict.Count {0}, expected {1}", sortDict.Count, StoreItemCount));
                    }
                    for (int i2 = 0; i2 < 500; i2++)
                    {
                        sortDict[i2] = i2 * 2 + i;
                    }
                }
            }
        }