/// <summary> /// Gets/sets a value. /// </summary> /// <param name="index"></param> /// <returns></returns> public T this[long index] { get { if (index >= _virtualSize) { // index out of range! throw new IndexOutOfRangeException(); } if (_lastAccessedBlock != null && _lastAccessedBlock.Index <= index && (_lastAccessedBlock.Index + _blockSize) > index) { // the last accessed block is contains the requested value. return(_lastAccessedBlock.Data[index - _lastAccessedBlock.Index]); } // calculate block index. long blockIndex = index / _blockSize; // get block. ArrayBlock block; if (_arrayBlocks.TryGetValue(blockIndex, out block)) { // return the value from this block. _lastAccessedBlock = block; // set last accessed block. return(_lastAccessedBlock.Data[index - _lastAccessedBlock.Index]); } return(default(T)); // no block was found! } set { if (index >= _virtualSize) { // index out of range! throw new IndexOutOfRangeException(); } if (_lastAccessedBlock != null && _lastAccessedBlock.Index <= index && (_lastAccessedBlock.Index + _blockSize) > index) { // the last accessed block is contains the requested value. _lastAccessedBlock.Data[index - _lastAccessedBlock.Index] = value; return; } // calculate block index. long blockIndex = index / _blockSize; // get block. ArrayBlock block; if (!_arrayBlocks.TryGetValue(blockIndex, out block) && value != null) { // return the value from this block. block = new ArrayBlock(blockIndex * _blockSize, _blockSize); _arrayBlocks.Add(blockIndex, block); } if (block != null) { // the block exists. _lastAccessedBlock = block; // set last accessed block. _lastAccessedBlock.Data[index - _lastAccessedBlock.Index] = value; } } }
static public void ArrayBlock() { ArrayBlock obj = new ArrayBlock(); obj.PlaceObject(); }