public void AddFirst(DataBlock block) { if (this._firstBlock == null) this.AddBlockToEmptyMap(block); else this.AddBeforeInternal(this._firstBlock, block); }
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; }
internal Enumerator(DataMap map) { this._map = map; this._version = map._version; this._current = (DataBlock)null; this._index = -1; }
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 InvalidateBlock(DataBlock block) { block._map = (DataMap)null; block._nextBlock = (DataBlock)null; block._previousBlock = (DataBlock)null; }
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); }
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); } }
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 void Remove(DataBlock block) { this.RemoveInternal(block); }
public void AddBefore(DataBlock block, DataBlock newBlock) { this.AddBeforeInternal(block, newBlock); }
public void AddAfter(DataBlock block, DataBlock newBlock) { this.AddAfterInternal(block, newBlock); }
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; }
public void AddAfter(DataBlock block, DataBlock newBlock) { this.AddAfterInternal(block, newBlock); }
public DataBlock Replace(DataBlock block, DataBlock newBlock) { this.AddAfterInternal(block, newBlock); this.RemoveInternal(block); return newBlock; }
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 void AddBlockToEmptyMap(DataBlock block) { block._map = this; block._nextBlock = (DataBlock)null; block._previousBlock = (DataBlock)null; this._firstBlock = block; ++this._version; ++this._count; }
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; }
public DataBlock Replace(DataBlock block, DataBlock newBlock) { this.AddAfterInternal(block, newBlock); this.RemoveInternal(block); return(newBlock); }