public bool Get(int index) { if (index < 0 || index >= Length) { throw new ArgumentOutOfRangeException(nameof(index), index, SR.ArgumentOutOfRange_Index); } Contract.EndContractBlock(); return (m_array[index / 32] & (1 << (index % 32))) != 0; }
/// <summary> /// Creates a RLEBitset from a BitArray. /// </summary> /// <param name="bits">a BitArray</param> /// <returns>an RLEBitset</returns> public static IBitset CreateFrom(BitArray bits) { RLEBitset rtnVal = new RLEBitset(); rtnVal._Length = bits.Length; Run currRun = new Run(); for (int i = 0; i < bits.Count; i++) { if (bits.Get(i) == true) { currRun.StartIndex = i; currRun.EndIndex = i; for (int j = i + 1; j < bits.Count; j++) { if (bits.Get(j)) { currRun.EndIndex = j; } else { break; } } i = currRun.EndIndex; //move the counter to the end of the run we just found rtnVal._RunArray.Add(currRun); currRun = new Run(); } } return rtnVal; }