public bool this[long idx] { get { int index = (int)(idx / (long)this._blockSize); if (this._data[index] == null) { return(false); } int num = (int)(idx % (long)this._blockSize); return(this._data[index][(long)num]); } set { int index = (int)(idx / (long)this._blockSize); LargeBitArray32 largeBitArray32_1 = this._data[index]; if (largeBitArray32_1 == null) { if (!value) { return; } LargeBitArray32 largeBitArray32_2 = new LargeBitArray32((long)this._blockSize); int num = (int)(idx % (long)this._blockSize); largeBitArray32_2[(long)num] = true; this._data[index] = largeBitArray32_2; } else { int num = (int)(idx % (long)this._blockSize); largeBitArray32_1[(long)num] = value; } } }
/// <summary> /// Gets or sets the value at the given index. /// </summary> /// <param name="idx"></param> /// <returns></returns> public bool this[long idx] { get { int blockId = (int)(idx / _blockSize); var block = _data[blockId]; if (block != null) { // the block actually exists. int blockIdx = (int)(idx % _blockSize); return(_data[blockId][blockIdx]); } return(false); } set { int blockId = (int)(idx / _blockSize); var block = _data[blockId]; if (block == null) { // block is not there. if (value) { // only add new block if true. block = new LargeBitArray32(_blockSize); int blockIdx = (int)(idx % _blockSize); block[blockIdx] = true; _data[blockId] = block; } } else { // set value at block. int blockIdx = (int)(idx % _blockSize); block[blockIdx] = value; } } }
public void TestLargeBitArray32() { var size = 32 * 1000; var referenceArray = new bool[size]; var array = new LargeBitArray32(size); // test size. Assert.AreEqual(referenceArray.Length, array.Length); // add random data. for (int idx = 0; idx < 1000; idx++) { referenceArray[idx] = true; array[idx] = true; Assert.IsTrue(array[idx]); } // compare both. for (int idx = 0; idx < referenceArray.Length; idx++) { Assert.AreEqual(referenceArray[idx], array[idx]); } // remove random data. for (int idx = 0; idx < 1000; idx++) { referenceArray[idx] = false; array[idx] = false; } // compare both. for (int idx = 0; idx < referenceArray.Length; idx++) { Assert.AreEqual(referenceArray[idx], array[idx]); } }
/// <summary> /// Gets or sets the value at the given index. /// </summary> /// <param name="idx"></param> /// <returns></returns> public bool this[long idx] { get { int blockId = (int)(idx / _blockSize); var block = _data[blockId]; if (block != null) { // the block actually exists. int blockIdx = (int)(idx % _blockSize); return _data[blockId][blockIdx]; } return false; } set { int blockId = (int)(idx / _blockSize); var block = _data[blockId]; if (block == null) { // block is not there. if (value) { // only add new block if true. block = new LargeBitArray32(_blockSize); int blockIdx = (int)(idx % _blockSize); block[blockIdx] = true; _data[blockId] = block; } } else { // set value at block. int blockIdx = (int)(idx % _blockSize); block[blockIdx] = value; } } }