Example #1
0
 public void AddFirst(DataBlock block)
 {
     if (this._firstBlock == null)
         this.AddBlockToEmptyMap(block);
     else
         this.AddBeforeInternal(this._firstBlock, block);
 }
Example #2
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 = (DataBlock)null;
 }
Example #3
0
 internal Enumerator(DataMap map)
 {
     this._map = map;
     this._version = map._version;
     this._current = (DataBlock)null;
     this._index = -1;
 }
Example #4
0
 private void RemoveInternal(DataBlock block)
 {
     DataBlock dataBlock1 = block._previousBlock;
     DataBlock dataBlock2 = block._nextBlock;
     if (dataBlock1 != null)
         dataBlock1._nextBlock = dataBlock2;
     if (dataBlock2 != null)
         dataBlock2._previousBlock = dataBlock1;
     if (this._firstBlock == block)
         this._firstBlock = dataBlock2;
     this.InvalidateBlock(block);
     --this._count;
     ++this._version;
 }
Example #5
0
 private void InvalidateBlock(DataBlock block)
 {
     block._map = (DataMap)null;
     block._nextBlock = (DataBlock)null;
     block._previousBlock = (DataBlock)null;
 }
Example #6
0
 private void InvalidateBlock(DataBlock block)
 {
     block._map           = (DataMap)null;
     block._nextBlock     = (DataBlock)null;
     block._previousBlock = (DataBlock)null;
 }
Example #7
0
 public void AddLast(DataBlock block)
 {
     if (this._firstBlock == null)
         this.AddBlockToEmptyMap(block);
     else
         this.AddAfterInternal(this.GetLastBlock(), block);
 }
Example #8
0
 public void AddBefore(DataBlock block, DataBlock newBlock)
 {
     this.AddBeforeInternal(block, newBlock);
 }
Example #9
0
 public void Remove(DataBlock block)
 {
     this.RemoveInternal(block);
 }
 public void WriteByte(long index, byte value)
 {
     try
     {
         long            blockOffset;
         DataBlock       dataBlock        = this.GetDataBlock(index, out blockOffset);
         MemoryDataBlock memoryDataBlock1 = dataBlock as MemoryDataBlock;
         if (memoryDataBlock1 != null)
         {
             memoryDataBlock1.Data[index - blockOffset] = value;
         }
         else
         {
             FileDataBlock fileDataBlock1 = (FileDataBlock)dataBlock;
             if (blockOffset == index && dataBlock.PreviousBlock != null)
             {
                 MemoryDataBlock memoryDataBlock2 = dataBlock.PreviousBlock as MemoryDataBlock;
                 if (memoryDataBlock2 != null)
                 {
                     memoryDataBlock2.AddByteToEnd(value);
                     fileDataBlock1.RemoveBytesFromStart(1L);
                     if (fileDataBlock1.Length != 0L)
                     {
                         return;
                     }
                     this._dataMap.Remove((DataBlock)fileDataBlock1);
                     return;
                 }
             }
             if (blockOffset + fileDataBlock1.Length - 1L == index && dataBlock.NextBlock != null)
             {
                 MemoryDataBlock memoryDataBlock2 = dataBlock.NextBlock as MemoryDataBlock;
                 if (memoryDataBlock2 != null)
                 {
                     memoryDataBlock2.AddByteToStart(value);
                     fileDataBlock1.RemoveBytesFromEnd(1L);
                     if (fileDataBlock1.Length != 0L)
                     {
                         return;
                     }
                     this._dataMap.Remove((DataBlock)fileDataBlock1);
                     return;
                 }
             }
             FileDataBlock fileDataBlock2 = (FileDataBlock)null;
             if (index > blockOffset)
             {
                 fileDataBlock2 = new FileDataBlock(fileDataBlock1.FileOffset, index - blockOffset);
             }
             FileDataBlock fileDataBlock3 = (FileDataBlock)null;
             if (index < blockOffset + fileDataBlock1.Length - 1L)
             {
                 fileDataBlock3 = new FileDataBlock(fileDataBlock1.FileOffset + index - blockOffset + 1L, fileDataBlock1.Length - (index - blockOffset + 1L));
             }
             DataBlock block = this._dataMap.Replace(dataBlock, (DataBlock) new MemoryDataBlock(value));
             if (fileDataBlock2 != null)
             {
                 this._dataMap.AddBefore(block, (DataBlock)fileDataBlock2);
             }
             if (fileDataBlock3 != null)
             {
                 this._dataMap.AddAfter(block, (DataBlock)fileDataBlock3);
             }
         }
     }
     finally
     {
         this.OnChanged(EventArgs.Empty);
     }
 }
Example #11
0
 private FileDataBlock GetNextFileDataBlock(DataBlock block, long dataOffset, out long nextDataOffset)
 {
     nextDataOffset = dataOffset + block.Length;
     for (block = block.NextBlock; block != null; block = block.NextBlock)
     {
         FileDataBlock fileDataBlock = block as FileDataBlock;
         if (fileDataBlock != null)
             return fileDataBlock;
         nextDataOffset += block.Length;
     }
     return (FileDataBlock)null;
 }
Example #12
0
 public void Remove(DataBlock block)
 {
     this.RemoveInternal(block);
 }
Example #13
0
 public void AddBefore(DataBlock block, DataBlock newBlock)
 {
     this.AddBeforeInternal(block, newBlock);
 }
Example #14
0
 public void AddAfter(DataBlock block, DataBlock newBlock)
 {
     this.AddAfterInternal(block, newBlock);
 }
Example #15
0
 public bool MoveNext()
 {
     if (this._version != this._map._version)
         throw new InvalidOperationException("Collection was modified after the enumerator was instantiated.");
     if (this._index >= this._map.Count)
         return false;
     this._current = ++this._index != 0 ? this._current.NextBlock : this._map.FirstBlock;
     return this._index < this._map.Count;
 }
Example #16
0
 public void AddAfter(DataBlock block, DataBlock newBlock)
 {
     this.AddAfterInternal(block, newBlock);
 }
Example #17
0
 public DataBlock Replace(DataBlock block, DataBlock newBlock)
 {
     this.AddAfterInternal(block, newBlock);
     this.RemoveInternal(block);
     return newBlock;
 }
Example #18
0
 private 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 (this._firstBlock == block)
         this._firstBlock = newBlock;
     ++this._version;
     ++this._count;
 }
Example #19
0
 private void AddBlockToEmptyMap(DataBlock block)
 {
     block._map = this;
     block._nextBlock = (DataBlock)null;
     block._previousBlock = (DataBlock)null;
     this._firstBlock = block;
     ++this._version;
     ++this._count;
 }
Example #20
0
 public void Clear()
 {
     DataBlock nextBlock;
     for (DataBlock block = this.FirstBlock; block != null; block = nextBlock)
     {
         nextBlock = block.NextBlock;
         this.InvalidateBlock(block);
     }
     this._firstBlock = (DataBlock)null;
     this._count = 0;
     ++this._version;
 }
Example #21
0
 public DataBlock Replace(DataBlock block, DataBlock newBlock)
 {
     this.AddAfterInternal(block, newBlock);
     this.RemoveInternal(block);
     return(newBlock);
 }