Esempio n. 1
0
 public void AddFirst(DataBlock block)
 {
     if (_firstBlock == null)
         AddBlockToEmptyMap(block);
     else
         AddBeforeInternal(_firstBlock, block);
 }
Esempio n. 2
0
 public void AddLast(DataBlock block)
 {
     if (_firstBlock == null)
         AddBlockToEmptyMap(block);
     else
         AddAfterInternal(GetLastBlock(), block);
 }
Esempio n. 3
0
 private void AddAfterInternal(DataBlock block, DataBlock newBlock) {
     newBlock.PreviousBlock = block;
     newBlock.NextBlock = block.NextBlock;
     newBlock.Map = this;
     if (block.NextBlock != null)
         block.NextBlock.PreviousBlock = newBlock;
     block.NextBlock = newBlock;
     Version++;
     Count++;
 }
Esempio n. 4
0
 public void Clear() {
     var block = FirstBlock;
     while (block != null) {
         var nextBlock = block.NextBlock;
         InvalidateBlock(block);
         block = nextBlock;
     }
     FirstBlock = null;
     Count = 0;
     Version++;
 }
Esempio n. 5
0
            public bool MoveNext()
            {
                if (_index >= _map.Count)
                {
                    return false;
                }

                if (++_index == 0)
                {
                    _current = null;
                }
                else
                {
                    _current = null;
                }

                return (_index < _map.Count);
            }
Esempio n. 6
0
 public void AddBefore(DataBlock block, DataBlock newBlock)
 {
     AddBeforeInternal(block, newBlock);
 }
Esempio n. 7
0
 public void Remove(DataBlock block)
 {
     RemoveInternal(block);
 }
Esempio n. 8
0
 void InvalidateBlock(DataBlock block)
 {
     block._map           = null;
     block._nextBlock     = null;
     block._previousBlock = null;
 }
Esempio n. 9
0
            public bool MoveNext()
            {
                if (this._version != _map._version)
                {
                    throw new InvalidOperationException("Collection was modified after the enumerator was instantiated.");
                }

                if (_index >= _map.Count)
                {
                    return false;
                }

                if (++_index == 0)
                {
                    _current = _map.FirstBlock;
                }
                else
                {
                    _current = _current.NextBlock;
                }

                return (_index < _map.Count);
            }
Esempio n. 10
0
 public void AddAfter(DataBlock block, DataBlock newBlock)
 {
     AddAfterInternal(block, newBlock);
 }
Esempio n. 11
0
        void RemoveInternal(DataBlock block)
        {
            DataBlock previousBlock = block._previousBlock;
            DataBlock nextBlock = block._nextBlock;

            if (previousBlock != null)
            {
                previousBlock._nextBlock = nextBlock;
            }

            if (nextBlock != null)
            {
                nextBlock._previousBlock = previousBlock;
            }

            if (_firstBlock == block)
            {
                _firstBlock = nextBlock;
            }

            InvalidateBlock(block);

            _count--;
            _version++;
        }
Esempio n. 12
0
        void AddBlockToEmptyMap(DataBlock block)
        {
            block._map = this;
            block._nextBlock = null;
            block._previousBlock = null;

            _firstBlock = block;
            _version++;
            _count++;
        }
Esempio n. 13
0
 private static void InvalidateBlock(DataBlock block)
 {
     block.Map           = null;
     block.NextBlock     = null;
     block.PreviousBlock = null;
 }
Esempio n. 14
0
        void AddAfterInternal(DataBlock block, DataBlock newBlock)
        {
            newBlock._previousBlock = block;
            newBlock._nextBlock = block._nextBlock;
            newBlock._map = this;

            if (block._nextBlock != null)
            {
                block._nextBlock._previousBlock = newBlock;
            }
            block._nextBlock = newBlock;

            this._version++;
            this._count++;
        }
Esempio n. 15
0
 private void RemoveInternal(DataBlock block) {
     var previousBlock = block.PreviousBlock;
     var nextBlock = block.NextBlock;
     if (previousBlock != null)
         previousBlock.NextBlock = nextBlock;
     if (nextBlock != null)
         nextBlock.PreviousBlock = previousBlock;
     if (FirstBlock == block)
         FirstBlock = nextBlock;
     InvalidateBlock(block);
     Count--;
     Version++;
 }
Esempio n. 16
0
 void IEnumerator.Reset() {
     if (_version != _map.Version)
         throw new InvalidOperationException("Collection was modified after the enumerator was instantiated.");
     _index = -1;
     _current = null;
 }
Esempio n. 17
0
 public bool MoveNext() {
     if (_version != _map.Version)
         throw new InvalidOperationException("Collection was modified after the enumerator was instantiated.");
     if (_index >= _map.Count)
         return false;
     _current = ++_index == 0 ? _map.FirstBlock : _current.NextBlock;
     return (_index < _map.Count);
 }
Esempio n. 18
0
 private void AddBlockToEmptyMap(DataBlock block) {
     block.Map = this;
     block.NextBlock = null;
     block.PreviousBlock = null;
     FirstBlock = block;
     Version++;
     Count++;
 }
Esempio n. 19
0
 private static void InvalidateBlock(DataBlock block) {
     block.Map = null;
     block.NextBlock = null;
     block.PreviousBlock = null;
 }
Esempio n. 20
0
 public void Clear()
 {
     DataBlock block = FirstBlock;
     while (block != null)
     {
         DataBlock nextBlock = block.NextBlock;
         InvalidateBlock(block);
         block = nextBlock;
     }
     _firstBlock = null;
     _count = 0;
     _version++;
 }
Esempio n. 21
0
 void IEnumerator.Reset()
 {
     _index = -1;
     _current = null;
 }
Esempio n. 22
0
        void AddBeforeInternal(DataBlock block, DataBlock newBlock)
        {
            newBlock._nextBlock = block;
            newBlock._previousBlock = block._previousBlock;
            newBlock._map = this;

            if (block._previousBlock != null)
            {
                block._previousBlock._nextBlock = newBlock;
            }
            block._previousBlock = newBlock;

            if (_firstBlock == block)
            {
                _firstBlock = newBlock;
            }
            this._version++;
            this._count++;
        }
 // Token: 0x06000369 RID: 873 RVA: 0x000122D4 File Offset: 0x000104D4
 public void WriteByte(long index, byte value)
 {
     try
     {
         long            num;
         DataBlock       dataBlock       = this.GetDataBlock(index, out num);
         MemoryDataBlock memoryDataBlock = dataBlock as MemoryDataBlock;
         if (memoryDataBlock != null)
         {
             memoryDataBlock.Data[(int)(checked ((IntPtr)(unchecked (index - num))))] = value;
         }
         else
         {
             FileDataBlock fileDataBlock = (FileDataBlock)dataBlock;
             if (num == index && dataBlock.PreviousBlock != null)
             {
                 MemoryDataBlock memoryDataBlock2 = dataBlock.PreviousBlock as MemoryDataBlock;
                 if (memoryDataBlock2 != null)
                 {
                     memoryDataBlock2.AddByteToEnd(value);
                     fileDataBlock.RemoveBytesFromStart(1L);
                     if (fileDataBlock.Length == 0L)
                     {
                         this._dataMap.Remove(fileDataBlock);
                     }
                     return;
                 }
             }
             if (num + fileDataBlock.Length - 1L == index && dataBlock.NextBlock != null)
             {
                 MemoryDataBlock memoryDataBlock3 = dataBlock.NextBlock as MemoryDataBlock;
                 if (memoryDataBlock3 != null)
                 {
                     memoryDataBlock3.AddByteToStart(value);
                     fileDataBlock.RemoveBytesFromEnd(1L);
                     if (fileDataBlock.Length == 0L)
                     {
                         this._dataMap.Remove(fileDataBlock);
                     }
                     return;
                 }
             }
             FileDataBlock fileDataBlock2 = null;
             if (index > num)
             {
                 fileDataBlock2 = new FileDataBlock(fileDataBlock.FileOffset, index - num);
             }
             FileDataBlock fileDataBlock3 = null;
             if (index < num + fileDataBlock.Length - 1L)
             {
                 fileDataBlock3 = new FileDataBlock(fileDataBlock.FileOffset + index - num + 1L, fileDataBlock.Length - (index - num + 1L));
             }
             dataBlock = this._dataMap.Replace(dataBlock, new MemoryDataBlock(value));
             if (fileDataBlock2 != null)
             {
                 this._dataMap.AddBefore(dataBlock, fileDataBlock2);
             }
             if (fileDataBlock3 != null)
             {
                 this._dataMap.AddAfter(dataBlock, fileDataBlock3);
             }
         }
     }
     finally
     {
         this.OnChanged(EventArgs.Empty);
     }
 }
Esempio n. 24
0
 void InvalidateBlock(DataBlock block)
 {
     block._map = null;
     block._nextBlock = null;
     block._previousBlock = null;
 }
Esempio n. 25
0
 void IEnumerator.Reset()
 {
     this._index = -1;
     this._current = null;
 }
Esempio n. 26
0
 internal Enumerator(DataMap map)
 {
     _map = map;
     _version = map._version;
     _current = null;
     _index = -1;
 }
Esempio n. 27
0
        /// <summary>
        /// See <see cref="IByteProvider.WriteByte" /> for more information.
        /// </summary>
        public void WriteByte(long index, byte value)
        {
            try
            {
                // Find the block affected.
                long      blockOffset;
                DataBlock block = GetDataBlock(index, out blockOffset);

                // If the byte is already in a memory block, modify it.
                MemoryDataBlock memoryBlock = block as MemoryDataBlock;
                if (memoryBlock != null)
                {
                    memoryBlock.Data[index - blockOffset] = value;
                    return;
                }

                FileDataBlock fileBlock = (FileDataBlock)block;

                // If the byte changing is the first byte in the block and the previous block is a memory block, extend that.
                if (blockOffset == index && block.PreviousBlock != null)
                {
                    MemoryDataBlock previousMemoryBlock = block.PreviousBlock as MemoryDataBlock;
                    if (previousMemoryBlock != null)
                    {
                        previousMemoryBlock.AddByteToEnd(value);
                        fileBlock.RemoveBytesFromStart(1);
                        if (fileBlock.Length == 0)
                        {
                            _dataMap.Remove(fileBlock);
                        }
                        return;
                    }
                }

                // If the byte changing is the last byte in the block and the next block is a memory block, extend that.
                if (blockOffset + fileBlock.Length - 1 == index && block.NextBlock != null)
                {
                    MemoryDataBlock nextMemoryBlock = block.NextBlock as MemoryDataBlock;
                    if (nextMemoryBlock != null)
                    {
                        nextMemoryBlock.AddByteToStart(value);
                        fileBlock.RemoveBytesFromEnd(1);
                        if (fileBlock.Length == 0)
                        {
                            _dataMap.Remove(fileBlock);
                        }
                        return;
                    }
                }

                // Split the block into a prefix and a suffix and place a memory block in-between.
                FileDataBlock prefixBlock = null;
                if (index > blockOffset)
                {
                    prefixBlock = new FileDataBlock(fileBlock.FileOffset, index - blockOffset);
                }

                FileDataBlock suffixBlock = null;
                if (index < blockOffset + fileBlock.Length - 1)
                {
                    suffixBlock = new FileDataBlock(
                        fileBlock.FileOffset + index - blockOffset + 1,
                        fileBlock.Length - (index - blockOffset + 1));
                }

                block = _dataMap.Replace(block, new MemoryDataBlock(value));

                if (prefixBlock != null)
                {
                    _dataMap.AddBefore(block, prefixBlock);
                }

                if (suffixBlock != null)
                {
                    _dataMap.AddAfter(block, suffixBlock);
                }
            }
            finally
            {
                OnChanged(EventArgs.Empty);
            }
        }
Esempio n. 28
0
            void IEnumerator.Reset()
            {
                if (this._version != this._map._version)
                {
                    throw new InvalidOperationException("Collection was modified after the enumerator was instantiated.");
                }

                this._index = -1;
                this._current = null;
            }
Esempio n. 29
0
        /// <summary>
        /// See <see cref="IByteProvider.InsertBytes" /> for more information.
        /// </summary>
        public void InsertBytes(long index, byte[] bs)
        {
            try
            {
                // Find the block affected.
                long      blockOffset;
                DataBlock block = GetDataBlock(index, out blockOffset);

                // If the insertion point is in a memory block, just insert it.
                MemoryDataBlock memoryBlock = block as MemoryDataBlock;
                if (memoryBlock != null)
                {
                    memoryBlock.InsertBytes(index - blockOffset, bs);
                    return;
                }

                FileDataBlock fileBlock = (FileDataBlock)block;

                // If the insertion point is at the start of a file block, and the previous block is a memory block, append it to that block.
                if (blockOffset == index && block.PreviousBlock != null)
                {
                    MemoryDataBlock previousMemoryBlock = block.PreviousBlock as MemoryDataBlock;
                    if (previousMemoryBlock != null)
                    {
                        previousMemoryBlock.InsertBytes(previousMemoryBlock.Length, bs);
                        return;
                    }
                }

                // Split the block into a prefix and a suffix and place a memory block in-between.
                FileDataBlock prefixBlock = null;
                if (index > blockOffset)
                {
                    prefixBlock = new FileDataBlock(fileBlock.FileOffset, index - blockOffset);
                }

                FileDataBlock suffixBlock = null;
                if (index < blockOffset + fileBlock.Length)
                {
                    suffixBlock = new FileDataBlock(
                        fileBlock.FileOffset + index - blockOffset,
                        fileBlock.Length - (index - blockOffset));
                }

                block = _dataMap.Replace(block, new MemoryDataBlock(bs));

                if (prefixBlock != null)
                {
                    _dataMap.AddBefore(block, prefixBlock);
                }

                if (suffixBlock != null)
                {
                    _dataMap.AddAfter(block, suffixBlock);
                }
            }
            finally
            {
                _totalLength += bs.Length;
                OnLengthChanged(EventArgs.Empty);
                OnChanged(EventArgs.Empty);
            }
        }
Esempio n. 30
0
 public void AddBefore(DataBlock block, DataBlock newBlock)
 {
     AddBeforeInternal(block, newBlock);
 }
Esempio n. 31
0
 private void InvalidateBlock(DataBlock block)
 {
     block._map           = (DataMap)null;
     block._nextBlock     = (DataBlock)null;
     block._previousBlock = (DataBlock)null;
 }
Esempio n. 32
0
		public DataBlock Replace(DataBlock block, DataBlock newBlock)
		{
			AddAfterInternal(block, newBlock);
			RemoveInternal(block);
			return newBlock;
		}
Esempio n. 33
0
 public DataBlock Replace(DataBlock block, DataBlock newBlock)
 {
     AddAfterInternal(block, newBlock);
     RemoveInternal(block);
     return(newBlock);
 }
Esempio n. 34
0
 public void AddAfter(DataBlock block, DataBlock newBlock)
 {
     AddAfterInternal(block, newBlock);
 }
Esempio n. 35
0
 void IEnumerator.Reset()
 {
     _index   = -1;
     _current = null;
 }
Esempio n. 36
0
 public void Remove(DataBlock block)
 {
     RemoveInternal(block);
 }
 FileDataBlock GetNextFileDataBlock(DataBlock block, long dataOffset, out long nextDataOffset)
 {
     nextDataOffset = dataOffset + block.Length;
     block = block.NextBlock;
     while (block != null)
     {
         FileDataBlock fileBlock = block as FileDataBlock;
         if (fileBlock != null)
         {
             return fileBlock;
         }
         nextDataOffset += block.Length;
         block = block.NextBlock;
     }
     return null;
 }
 FileDataBlock GetNextFileDataBlock(DataBlock block, long dataOffset, out long nextDataOffset)
 {
     // Iterate over the remaining blocks until a file block is encountered.
     nextDataOffset = dataOffset + block.Length;
     block = block.NextBlock;
     while (block != null)
     {
         FileDataBlock fileBlock = block as FileDataBlock;
         if (fileBlock != null)
         {
             return fileBlock;
         }
         nextDataOffset += block.Length;
         block = block.NextBlock;
     }
     return null;
 }
Esempio n. 39
0
 void IEnumerator.Reset()
 {
     this._index   = -1;
     this._current = null;
 }