A dynamic array with an unlimited number of bits. More...
Public Member Functions | |
BitArray () | |
BitArray (BitArray const copy) | |
BitArray (SparseArray const from) | |
BitArray (unsigned long long int init_value) | |
clear () | |
Sets all the bits in the BitArray off. | |
clearBit (int index) | |
Sets the nth bit off. | |
clearRange (int low_bit, int size) | |
Sets the indicated range of bits off. | |
int | compareTo (BitArray const other) |
Returns a number less than zero if this BitArray sorts before the indicated other BitArray, greater than zero if it sorts after, or 0 if they are equivalent. | |
unsigned long long int | extract (int low_bit, int size) |
Returns a word that represents only the indicated range of bits within this BitArray, shifted to the least-significant position. | |
bool | getBit (int index) |
Returns true if the nth bit is set, false if it is cleared. | |
bool | getHighestBits () |
Returns true if the infinite set of bits beyond get_num_bits() are all on, or false of they are all off. | |
int | getHighestOffBit () |
Returns the index of the highest 0 bit in the array. | |
int | getHighestOnBit () |
Returns the index of the highest 1 bit in the array. | |
int | getLowestOffBit () |
Returns the index of the lowest 0 bit in the array. | |
int | getLowestOnBit () |
Returns the index of the lowest 1 bit in the array. | |
int | getNextHigherDifferentBit (int low_bit) |
Returns the index of the next bit in the array, above low_bit, whose value is different that the value of low_bit. | |
int | getNumBits () |
Returns the current number of possibly different bits in this array. | |
int | getNumOffBits () |
Returns the number of bits that are set to 0 in the array. | |
int | getNumOnBits () |
Returns the number of bits that are set to 1 in the array. | |
int | getNumWords () |
Returns the number of possibly-unique words stored in the array. | |
BitMaskunsigned long long | getWord (int n) |
bool | hasAllOf (int low_bit, int size) |
Returns true if all bits in the indicated range are set, false otherwise. | |
bool | hasAnyOf (int low_bit, int size) |
Returns true if any bit in the indicated range is set, false otherwise. | |
bool | hasBitsInCommon (BitArray const other) |
Returns true if this BitArray has any "one" bits in common with the other one, false otherwise. | |
invertInPlace () | |
Inverts all the bits in the BitArray. | |
bool | isAllOn () |
Returns true if the entire bitmask is one, false otherwise. | |
bool | isZero () |
Returns true if the entire bitmask is zero, false otherwise. | |
bool | operator!= (BitArray const other) |
BitArray | operator& (BitArray const other) |
BitArray | operator&= (BitArray const other) |
bool | operator< (BitArray const other) |
Returns true if the unsigned integer which is represented by this BitArray is less than that of the other one, false otherwise. | |
BitArray | operator<< (int shift) |
BitArray | operator<<= (int shift) |
Logical left shift. | |
BitArray | operator= (BitArray const copy) |
bool | operator== (BitArray const other) |
BitArray | operator>> (int shift) |
BitArray | operator>>= (int shift) |
Logical right shift. | |
BitArray | operator^ (BitArray const other) |
BitArray | operator^= (BitArray const other) |
BitArray | operator| (BitArray const other) |
BitArray | operator|= (BitArray const other) |
BitArray | operator~ () |
output (ostream out) | |
Writes the BitArray out as a hex number. | |
outputBinary (ostream out, int spaces_every) | |
Writes the BitArray out as a binary number, with spaces every four bits. | |
outputBinary (ostream out) | |
Writes the BitArray out as a binary number, with spaces every four bits. | |
outputHex (ostream out, int spaces_every) | |
Writes the BitArray out as a hexadecimal number, with spaces every four digits. | |
outputHex (ostream out) | |
Writes the BitArray out as a hexadecimal number, with spaces every four digits. | |
setBit (int index) | |
Sets the nth bit on. | |
setBitTo (int index, bool value) | |
Sets the nth bit either on or off, according to the indicated bool value. | |
setRange (int low_bit, int size) | |
Sets the indicated range of bits on. | |
setRangeTo (bool value, int low_bit, int size) | |
Sets the indicated range of bits to either on or off. | |
setWord (int n, BitMaskunsigned long long int, 64 value) | |
Replaces the nth word in the array. | |
store (unsigned long long int value, int low_bit, int size) | |
Stores the indicated word into the indicated range of bits with this BitArray. | |
write (ostream out, int indent_level) | |
Writes the BitArray out as a binary or a hex number, according to the number of bits. | |
write (ostream out) | |
Writes the BitArray out as a binary or a hex number, according to the number of bits. | |
Static Public Member Functions | |
static BitArray | allOff () |
Returns a BitArray whose bits are all off. | |
static BitArray | allOn () |
Returns a BitArray with an infinite array of bits, all on. | |
static BitArray | bit (int index) |
Returns a BitArray with only the indicated bit on. | |
static TypeHandle | getClassType () |
static int | getMaxNumBits () |
If get_max_num_bits() returned true, this method may be called to return the maximum number of bits that may be stored in this structure. | |
static int | getNumBitsPerWord () |
Returns the number of bits stored per word internally. | |
static bool | hasMaxNumBits () |
Returns true if there is a maximum number of bits that may be stored in this structure, false otherwise. | |
static BitArray | lowerOn (int on_bits) |
Returns a BitArray whose lower on_bits bits are on. | |
static BitArray | range (int low_bit, int size) |
Returns a BitArray whose size bits, beginning at low_bit, are on. | |
Public Attributes | |
BitMaskunsigned long long | int |
Returns the nth word in the array. |
A dynamic array with an unlimited number of bits.
This is similar to a BitMask, except it appears to contain an infinite number of bits. You can use it very much as you would use a BitMask.
BitArray | ( | ) |
BitArray | ( | SparseArray const | from | ) |
Sets the nth bit off.
If n >= get_num_bits(), this automatically extends the array.
clearRange | ( | int | low_bit, |
int | size | ||
) |
Sets the indicated range of bits off.
Returns a word that represents only the indicated range of bits within this BitArray, shifted to the least-significant position.
size must be <= get_num_bits_per_word().
Returns true if the nth bit is set, false if it is cleared.
It is valid for n to increase beyond get_num_bits(), but the return value get_num_bits() will always be the same.
static TypeHandle getClassType | ( | ) | [static] |
bool getHighestBits | ( | ) |
Returns true if the infinite set of bits beyond get_num_bits() are all on, or false of they are all off.
int getHighestOffBit | ( | ) |
Returns the index of the highest 0 bit in the array.
Returns -1 if there are no 0 bits or if there an infinite number of 1 bits.
int getHighestOnBit | ( | ) |
Returns the index of the highest 1 bit in the array.
Returns -1 if there are no 1 bits or if there an infinite number of 1 bits.
int getLowestOffBit | ( | ) |
Returns the index of the lowest 0 bit in the array.
Returns -1 if there are no 0 bits.
int getLowestOnBit | ( | ) |
Returns the index of the lowest 1 bit in the array.
Returns -1 if there are no 1 bits.
static int getMaxNumBits | ( | ) | [static] |
If get_max_num_bits() returned true, this method may be called to return the maximum number of bits that may be stored in this structure.
It is an error to call this if get_max_num_bits() return false.
It is always an error to call this method. The BitArray has no maximum number of bits. This method is defined so generic programming algorithms can use BitMask or BitArray interchangeably.
int getNextHigherDifferentBit | ( | int | low_bit | ) |
Returns the index of the next bit in the array, above low_bit, whose value is different that the value of low_bit.
Returns low_bit again if all bits higher than low_bit have the same value.
This can be used to quickly iterate through all of the bits in the array.
int getNumBits | ( | ) |
Returns the current number of possibly different bits in this array.
There are actually an infinite number of bits, but every bit higher than this bit will have the same value, either 0 or 1 (see get_highest_bits()).
This number may grow and/or shrink automatically as needed.
static int getNumBitsPerWord | ( | ) | [static] |
int getNumOffBits | ( | ) |
Returns the number of bits that are set to 0 in the array.
Returns -1 if there are an infinite number of 0 bits.
int getNumOnBits | ( | ) |
Returns the number of bits that are set to 1 in the array.
Returns -1 if there are an infinite number of 1 bits.
int getNumWords | ( | ) |
Returns the number of possibly-unique words stored in the array.
Returns true if all bits in the indicated range are set, false otherwise.
Returns true if any bit in the indicated range is set, false otherwise.
bool hasBitsInCommon | ( | BitArray const | other | ) |
Returns true if this BitArray has any "one" bits in common with the other one, false otherwise.
This is equivalent to (array & other) != 0, but may be faster.
static bool hasMaxNumBits | ( | ) | [static] |
Returns true if there is a maximum number of bits that may be stored in this structure, false otherwise.
If this returns true, the number may be queried in get_max_num_bits().
This method always returns false. The BitArray has no maximum number of bits. This method is defined so generic programming algorithms can use BitMask or BitArray interchangeably.
invertInPlace | ( | ) |
Inverts all the bits in the BitArray.
This is equivalent to array = ~array.
bool isAllOn | ( | ) |
Returns true if the entire bitmask is one, false otherwise.
bool isZero | ( | ) |
Returns true if the entire bitmask is zero, false otherwise.
bool operator!= | ( | BitArray const | other | ) |
bool operator< | ( | BitArray const | other | ) |
Returns true if the unsigned integer which is represented by this BitArray is less than that of the other one, false otherwise.
Logical left shift.
The rightmost bits are filled in with zeroes. Since this is an infinite bit array, none of the bits on the left are lost.
bool operator== | ( | BitArray const | other | ) |
Logical right shift.
The rightmost bits are lost. Since this is an infinite bit array, there is no question of sign extension; there is no need to synthesize bits on the left.
outputBinary | ( | ostream | out, |
int | spaces_every | ||
) |
Writes the BitArray out as a binary number, with spaces every four bits.
outputBinary | ( | ostream | out | ) |
Writes the BitArray out as a binary number, with spaces every four bits.
Writes the BitArray out as a hexadecimal number, with spaces every four digits.
Writes the BitArray out as a hexadecimal number, with spaces every four digits.
Returns a BitArray whose size bits, beginning at low_bit, are on.
Sets the nth bit on.
If n >= get_num_bits(), this automatically extends the array.
Sets the nth bit either on or off, according to the indicated bool value.
setRangeTo | ( | bool | value, |
int | low_bit, | ||
int | size | ||
) |
Sets the indicated range of bits to either on or off.
Replaces the nth word in the array.
If n >= get_num_words(), this automatically extends the array.
Stores the indicated word into the indicated range of bits with this BitArray.
Writes the BitArray out as a binary or a hex number, according to the number of bits.
Writes the BitArray out as a binary or a hex number, according to the number of bits.
BitMaskunsigned long long int |
Returns the nth word in the array.
It is valid for n to be greater than get_num_words(), but the return value beyond get_num_words() will always be the same.