示例#1
0
 public void AddFirst(DataBlock block)
 {
     if (_firstBlock == null)
     {
         AddBlockToEmptyMap(block);
     }
     else
     {
         AddBeforeInternal(_firstBlock, block);
     }
 }
示例#2
0
 public void AddLast(DataBlock block)
 {
     if (_firstBlock == null)
     {
         AddBlockToEmptyMap(block);
     }
     else
     {
         AddAfterInternal(GetLastBlock(), block);
     }
 }
 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;
 }
示例#4
0
		public DataBlock Replace(DataBlock block, DataBlock newBlock)
		{
			AddAfterInternal(block, newBlock);
			RemoveInternal(block);
			return newBlock;
		}
示例#5
0
 public void Remove(DataBlock block)
 {
     RemoveInternal(block);
 }
示例#6
0
 public void AddAfter(DataBlock block, DataBlock newBlock)
 {
     AddAfterInternal(block, newBlock);
 }
示例#7
0
 public void AddBefore(DataBlock block, DataBlock newBlock)
 {
     AddBeforeInternal(block, newBlock);
 }
示例#8
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);
            }
示例#9
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;
            }
示例#10
0
        void AddBlockToEmptyMap(DataBlock block)
        {
            block._map = this;
            block._nextBlock = null;
            block._previousBlock = null;

            _firstBlock = block;
            _version++;
            _count++;
        }
示例#11
0
 internal Enumerator(DataMap map)
 {
     _map = map;
     _version = map._version;
     _current = null;
     _index = -1;
 }
示例#12
0
 void InvalidateBlock(DataBlock block)
 {
     block._map = null;
     block._nextBlock = null;
     block._previousBlock = null;
 }
示例#13
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++;
        }
示例#14
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++;
        }
示例#15
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++;
        }
示例#16
0
 public void Clear()
 {
     DataBlock block = FirstBlock;
     while (block != null)
     {
         DataBlock nextBlock = block.NextBlock;
         InvalidateBlock(block);
         block = nextBlock;
     }
     _firstBlock = null;
     _count = 0;
     _version++;
 }