public void AddFirst(DataBlock block) { if (this._firstBlock == null) this.AddBlockToEmptyMap(block); else this.AddBeforeInternal(this._firstBlock, block); }
private void AddBlockToEmptyMap(DataBlock block) { block._map = this; block._nextBlock = null; block._previousBlock = null; this._firstBlock = block; this._version++; this._count++; }
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; this._version++; this._count++; }
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++; }
public DataBlock Replace(DataBlock block, DataBlock newBlock) { this.AddAfterInternal(block, newBlock); this.RemoveInternal(block); return newBlock; }
private void RemoveInternal(DataBlock block) { DataBlock block2 = block._previousBlock; DataBlock block3 = block._nextBlock; if (block2 != null) { block2._nextBlock = block3; } if (block3 != null) { block3._previousBlock = block2; } if (this._firstBlock == block) { this._firstBlock = block3; } this.InvalidateBlock(block); this._count--; this._version++; }
public void Remove(DataBlock block) { this.RemoveInternal(block); }
private void InvalidateBlock(DataBlock block) { block._map = (DataMap)null; block._nextBlock = (DataBlock)null; block._previousBlock = (DataBlock)null; }
public void AddLast(DataBlock block) { if (this._firstBlock == null) { this.AddBlockToEmptyMap(block); } else { this.AddAfterInternal(this.GetLastBlock(), block); } }
public void AddBefore(DataBlock block, DataBlock newBlock) { this.AddBeforeInternal(block, newBlock); }
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; }
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; }
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; }
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; }
private FileDataBlock GetNextFileDataBlock(DataBlock block, long dataOffset, out long nextDataOffset) { nextDataOffset = dataOffset + block.Length; block = block.NextBlock; while (block != null) { FileDataBlock block2 = block as FileDataBlock; if (block2 != null) { return block2; } nextDataOffset += block.Length; block = block.NextBlock; } return null; }
internal Enumerator(DataMap map) { this._map = map; this._version = map._version; this._current = null; this._index = -1; }
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; } if (++this._index == 0) { this._current = this._map.FirstBlock; } else { this._current = this._current.NextBlock; } return (this._index < this._map.Count); }
public void AddAfter(DataBlock block, DataBlock newBlock) { this.AddAfterInternal(block, newBlock); }
public void WriteByte(long index, byte value) { try { long blockOffset; DataBlock dataBlock = 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; } _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; } _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 = _dataMap.Replace(dataBlock, (DataBlock) new MemoryDataBlock(value)); if (fileDataBlock2 != null) { _dataMap.AddBefore(block, (DataBlock)fileDataBlock2); } if (fileDataBlock3 == null) { return; } _dataMap.AddAfter(block, (DataBlock)fileDataBlock3); } } finally { OnChanged(EventArgs.Empty); } }
public void WriteByte(long index, byte value) { try { long num; DataBlock dataBlock = this.GetDataBlock(index, out num); MemoryDataBlock block2 = dataBlock as MemoryDataBlock; if (block2 != null) { block2.Data[(int)((IntPtr)(index - num))] = value; } else { FileDataBlock block = (FileDataBlock)dataBlock; if ((num == index) && (dataBlock.PreviousBlock != null)) { MemoryDataBlock previousBlock = dataBlock.PreviousBlock as MemoryDataBlock; if (previousBlock != null) { previousBlock.AddByteToEnd(value); block.RemoveBytesFromStart(1L); if (block.Length == 0L) { this._dataMap.Remove(block); } return; } } if ((((num + block.Length) - 1L) == index) && (dataBlock.NextBlock != null)) { MemoryDataBlock nextBlock = dataBlock.NextBlock as MemoryDataBlock; if (nextBlock != null) { nextBlock.AddByteToStart(value); block.RemoveBytesFromEnd(1L); if (block.Length == 0L) { this._dataMap.Remove(block); } return; } } FileDataBlock newBlock = null; if (index > num) { newBlock = new FileDataBlock(block.FileOffset, index - num); } FileDataBlock block7 = null; if (index < ((num + block.Length) - 1L)) { block7 = new FileDataBlock(((block.FileOffset + index) - num) + 1L, block.Length - ((index - num) + 1L)); } dataBlock = this._dataMap.Replace(dataBlock, new MemoryDataBlock(value)); if (newBlock != null) { this._dataMap.AddBefore(dataBlock, newBlock); } if (block7 != null) { this._dataMap.AddAfter(dataBlock, block7); } } } finally { this.OnChanged(EventArgs.Empty); } }
public void Clear() { DataBlock nextBlock; for (DataBlock block = this.FirstBlock; block != null; block = nextBlock) { nextBlock = block.NextBlock; this.InvalidateBlock(block); } this._firstBlock = null; this._count = 0; this._version++; }
private void InvalidateBlock(DataBlock block) { block._map = null; block._nextBlock = null; block._previousBlock = null; }
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; }
public DataBlock Replace(DataBlock block, DataBlock newBlock) { this.AddAfterInternal(block, newBlock); this.RemoveInternal(block); return(newBlock); }