9 [__DynamicallyInvokable]
21 private bool currentElement;
23 public virtual object Current
31 if (index >= bitarray.Count)
35 return currentElement;
39 internal BitArrayEnumeratorSimple(
BitArray bitarray)
41 this.bitarray = bitarray;
43 version = bitarray._version;
48 return MemberwiseClone();
51 public virtual bool MoveNext()
53 if (version != bitarray._version)
57 if (index < bitarray.
Count - 1)
60 currentElement = bitarray.
Get(index);
63 index = bitarray.
Count;
69 if (version != bitarray._version)
77 private const int BitsPerInt32 = 32;
79 private const int BytesPerInt32 = 4;
81 private const int BitsPerByte = 8;
83 private int[] m_array;
90 private object _syncRoot;
92 private const int _ShrinkThreshold = 256;
100 [__DynamicallyInvokable]
101 public bool this[
int index]
103 [__DynamicallyInvokable]
108 [__DynamicallyInvokable]
118 [__DynamicallyInvokable]
121 [__DynamicallyInvokable]
126 [__DynamicallyInvokable]
133 int arrayLength = GetArrayLength(value, 32);
134 if (arrayLength > m_array.Length || arrayLength + 256 < m_array.Length)
136 int[] array =
new int[arrayLength];
137 Array.
Copy(m_array, array, (arrayLength > m_array.Length) ? m_array.Length : arrayLength);
140 if (value > m_length)
142 int num = GetArrayLength(m_length, 32) - 1;
143 int num2 = m_length % 32;
146 m_array[num] &= (1 << num2) - 1;
148 Array.
Clear(m_array, num + 1, arrayLength - num - 1);
165 if (_syncRoot ==
null)
189 [__DynamicallyInvokable]
191 : this(length, defaultValue: false)
200 [__DynamicallyInvokable]
207 m_array =
new int[GetArrayLength(length, 32)];
209 int num = defaultValue ? (-1) : 0;
210 for (
int i = 0; i < m_array.Length; i++)
222 [__DynamicallyInvokable]
229 if (bytes.Length > 268435455)
233 m_array =
new int[GetArrayLength(bytes.Length, 4)];
234 m_length = bytes.Length * 8;
237 for (i = 0; bytes.Length - i >= 4; i += 4)
239 m_array[num++] = ((bytes[i] & 0xFF) | ((bytes[i + 1] & 0xFF) << 8) | ((bytes[i + 2] & 0xFF) << 16) | ((bytes[i + 3] & 0xFF) << 24));
241 switch (bytes.Length - i)
244 m_array[num] = (bytes[i + 2] & 0xFF) << 16;
247 m_array[num] |= (bytes[i + 1] & 0xFF) << 8;
250 m_array[num] |= (bytes[i] & 0xFF);
260 [__DynamicallyInvokable]
267 m_array =
new int[GetArrayLength(values.Length, 32)];
268 m_length = values.Length;
269 for (
int i = 0; i < values.Length; i++)
273 m_array[i / 32] |= 1 << i % 32;
284 [__DynamicallyInvokable]
291 if (values.Length > 67108863)
295 m_array =
new int[values.Length];
296 m_length = values.Length * 32;
297 Array.
Copy(values, m_array, values.Length);
305 [__DynamicallyInvokable]
312 int arrayLength = GetArrayLength(bits.m_length, 32);
313 m_array =
new int[arrayLength];
314 m_length = bits.m_length;
315 Array.
Copy(bits.m_array, m_array, arrayLength);
316 _version = bits._version;
325 [__DynamicallyInvokable]
326 public bool Get(
int index)
328 if (index < 0 || index >=
Length)
332 return (m_array[index / 32] & (1 << index % 32)) != 0;
341 [__DynamicallyInvokable]
342 public void Set(
int index,
bool value)
344 if (index < 0 || index >=
Length)
350 m_array[index / 32] |= 1 << index % 32;
354 m_array[index / 32] &= ~(1 << index % 32);
361 [__DynamicallyInvokable]
364 int num = value ? (-1) : 0;
365 int arrayLength = GetArrayLength(m_length, 32);
366 for (
int i = 0; i < arrayLength; i++)
381 [__DynamicallyInvokable]
388 if (
Length != value.Length)
392 int arrayLength = GetArrayLength(m_length, 32);
393 for (
int i = 0; i < arrayLength; i++)
395 m_array[i] &= value.m_array[i];
409 [__DynamicallyInvokable]
416 if (
Length != value.Length)
420 int arrayLength = GetArrayLength(m_length, 32);
421 for (
int i = 0; i < arrayLength; i++)
423 m_array[i] |= value.m_array[i];
437 [__DynamicallyInvokable]
444 if (
Length != value.Length)
448 int arrayLength = GetArrayLength(m_length, 32);
449 for (
int i = 0; i < arrayLength; i++)
451 m_array[i] ^= value.m_array[i];
459 [__DynamicallyInvokable]
462 int arrayLength = GetArrayLength(m_length, 32);
463 for (
int i = 0; i < arrayLength; i++)
465 m_array[i] = ~m_array[i];
497 Array.
Copy(m_array, 0, array, index, GetArrayLength(m_length, 32));
502 int arrayLength = GetArrayLength(m_length, 8);
503 if (array.Length - index < arrayLength)
507 byte[] array2 = (
byte[])array;
508 for (
int i = 0; i < arrayLength; i++)
510 array2[index + i] = (byte)((m_array[i / 4] >> i % 4 * 8) & 0xFF);
516 if (array.Length - index < m_length)
520 bool[] array3 = (
bool[])array;
521 for (
int j = 0; j < m_length; j++)
523 array3[index + j] = (((m_array[j / 32] >> j % 32) & 1) != 0);
535 bitArray._version = _version;
536 bitArray.m_length = m_length;
542 [__DynamicallyInvokable]
545 return new BitArrayEnumeratorSimple(
this);
548 private static int GetArrayLength(
int n,
int div)
554 return (n - 1) / div + 1;
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
BitArray(int[] values)
Initializes a new instance of the T:System.Collections.BitArray class that contains bit values copied...
bool IsSynchronized
Gets a value indicating whether access to the T:System.Collections.BitArray is synchronized (thread s...
static void Clear(Array array, int index, int length)
Sets a range of elements in an array to the default value of each element type.
The exception that is thrown when the value of an argument is outside the allowable range of values a...
void CopyTo(Array array, int index)
Copies the entire T:System.Collections.BitArray to a compatible one-dimensional T:System....
int? Length
Gets or sets the number of elements in the T:System.Collections.BitArray.
int Count
Gets the number of elements contained in the T:System.Collections.BitArray.
Manages a compact array of bit values, which are represented as Booleans, where true indicates that t...
bool IsReadOnly
Gets a value indicating whether the T:System.Collections.BitArray is read-only.
object SyncRoot
Gets an object that can be used to synchronize access to the T:System.Collections....
Exposes an enumerator, which supports a simple iteration over a non-generic collection....
BitArray Not()
Inverts all the bit values in the current T:System.Collections.BitArray, so that elements set to true...
Provides information about, and means to manipulate, the current environment and platform....
bool Get(int index)
Gets the value of the bit at a specific position in the T:System.Collections.BitArray.
IEnumerator GetEnumerator()
Returns an enumerator that iterates through the T:System.Collections.BitArray.
static int CompareExchange(ref int location1, int value, int comparand)
Compares two 32-bit signed integers for equality and, if they are equal, replaces the first value.
BitArray And(BitArray value)
Performs the bitwise AND operation between the elements of the current T:System.Collections....
BitArray(int length, bool defaultValue)
Initializes a new instance of the T:System.Collections.BitArray class that can hold the specified num...
Supports cloning, which creates a new instance of a class with the same value as an existing instance...
void Set(int index, bool value)
Sets the bit at a specific position in the T:System.Collections.BitArray to the specified value.
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
BitArray Xor(BitArray value)
Performs the bitwise exclusive OR operation between the elements of the current T:System....
BitArray Or(BitArray value)
Performs the bitwise OR operation between the elements of the current T:System.Collections....
void SetAll(bool value)
Sets all bits in the T:System.Collections.BitArray to the specified value.
The exception that is thrown when one of the arguments provided to a method is not valid.
static void Copy(Array sourceArray, Array destinationArray, int length)
Copies a range of elements from an T:System.Array starting at the first element and pastes them into ...
BitArray(byte[] bytes)
Initializes a new instance of the T:System.Collections.BitArray class that contains bit values copied...
BitArray(BitArray bits)
Initializes a new instance of the T:System.Collections.BitArray class that contains bit values copied...
Specifies that the class can be serialized.
The exception that is thrown when a method call is invalid for the object's current state.
BitArray(int length)
Initializes a new instance of the T:System.Collections.BitArray class that can hold the specified num...
object Clone()
Creates a shallow copy of the T:System.Collections.BitArray.
Defines size, enumerators, and synchronization methods for all nongeneric collections.
Provides atomic operations for variables that are shared by multiple threads.
Supports a simple iteration over a non-generic collection.
BitArray(bool[] values)
Initializes a new instance of the T:System.Collections.BitArray class that contains bit values copied...