Panda3D
Public Types | Public Member Functions | Static Public Member Functions | List of all members
BitArray Class Reference

A dynamic array with an unlimited number of bits. More...

Public Types

enum  { num_bits_per_word = 64 }
 

Public Member Functions

 __init__ ()
 
 __init__ (const BitArray)
 
 __init__ (BitArray::WordType init_value)
 
 __init__ (const SparseArray from)
 
 clear ()
 Sets all the bits in the BitArray off. More...
 
 clearBit (int index)
 Sets the nth bit off. More...
 
 clearRange (int low_bit, int size)
 Sets the indicated range of bits off. More...
 
int compareTo (const BitArray 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. More...
 
BitArray::WordType 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. More...
 
bool getBit (int index)
 Returns true if the nth bit is set, false if it is cleared. More...
 
bool getHighestBits ()
 Returns true if the infinite set of bits beyond get_num_bits() are all on, or false of they are all off. More...
 
int getHighestOffBit ()
 Returns the index of the highest 0 bit in the array. More...
 
int getHighestOnBit ()
 Returns the index of the highest 1 bit in the array. More...
 
int getLowestOffBit ()
 Returns the index of the lowest 0 bit in the array. More...
 
int getLowestOnBit ()
 Returns the index of the lowest 1 bit in the array. More...
 
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. More...
 
int getNumBits ()
 Returns the current number of possibly different bits in this array. More...
 
int getNumOffBits ()
 Returns the number of bits that are set to 0 in the array. More...
 
int getNumOnBits ()
 Returns the number of bits that are set to 1 in the array. More...
 
int getNumWords ()
 Returns the number of possibly-unique words stored in the array. More...
 
BitArray::MaskType getWord (int n)
 Returns the nth word in the array. More...
 
bool hasAllOf (int low_bit, int size)
 Returns true if all bits in the indicated range are set, false otherwise. More...
 
bool hasAnyOf (int low_bit, int size)
 Returns true if any bit in the indicated range is set, false otherwise. More...
 
bool hasBitsInCommon (const BitArray other)
 Returns true if this BitArray has any "one" bits in common with the other one, false otherwise. More...
 
 invertInPlace ()
 Inverts all the bits in the BitArray. More...
 
bool isAllOn ()
 Returns true if the entire bitmask is one, false otherwise. More...
 
bool isZero ()
 Returns true if the entire bitmask is zero, false otherwise. More...
 
bool operator != (const BitArray other)
 
BitArray operator & (const BitArray other)
 
BitArray operator &= (const BitArray other)
 
BitArray operator >> (int shift)
 
BitArray operator >>= (int shift)
 
BitArray operator ^ (const BitArray other)
 
BitArray operator ^= (const BitArray other)
 
BitArray operator ~ ()
 
bool operator< (const BitArray other)
 
BitArray operator<< (int shift)
 
BitArray operator<<= (int shift)
 
bool operator== (const BitArray other)
 
BitArray operator| (const BitArray other)
 
BitArray operator|= (const BitArray other)
 
 output (Ostream out)
 Writes the BitArray out as a hex number. More...
 
 outputBinary (Ostream out, int spaces_every)
 Writes the BitArray out as a binary number, with spaces every four bits. More...
 
 outputHex (Ostream out, int spaces_every)
 Writes the BitArray out as a hexadecimal number, with spaces every four digits. More...
 
 setBit (int index)
 Sets the nth bit on. More...
 
 setBitTo (int index, bool value)
 Sets the nth bit either on or off, according to the indicated bool value. More...
 
 setRange (int low_bit, int size)
 Sets the indicated range of bits on. More...
 
 setRangeTo (bool value, int low_bit, int size)
 Sets the indicated range of bits to either on or off. More...
 
 setWord (int n, BitArray::WordType value)
 Replaces the nth word in the array. More...
 
 store (BitArray::WordType value, int low_bit, int size)
 Stores the indicated word into the indicated range of bits with this BitArray. More...
 
 write (Ostream out, int indent_level)
 Writes the BitArray out as a binary or a hex number, according to the number of bits. More...
 

Static Public Member Functions

static BitArray allOff ()
 Returns a BitArray whose bits are all off. More...
 
static BitArray allOn ()
 Returns a BitArray with an infinite array of bits, all on. More...
 
static BitArray bit (int index)
 Returns a BitArray with only the indicated bit on. More...
 
static TypeHandle getClassType ()
 
static int getMaxNumBits ()
 
static int getNumBitsPerWord ()
 
static bool hasMaxNumBits ()
 
static BitArray lowerOn (int on_bits)
 Returns a BitArray whose lower on_bits bits are on. More...
 
static BitArray range (int low_bit, int size)
 Returns a BitArray whose size bits, beginning at low_bit, are on. More...
 

Detailed Description

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.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
Enumerator
num_bits_per_word 

Member Function Documentation

◆ __init__() [1/4]

__init__ ( )

◆ __init__() [2/4]

__init__ ( const  BitArray)

◆ __init__() [3/4]

__init__ ( BitArray::WordType  init_value)

◆ __init__() [4/4]

__init__ ( const SparseArray  from)

◆ allOff()

static BitArray allOff ( )
static

Returns a BitArray whose bits are all off.

◆ allOn()

static BitArray allOn ( )
static

Returns a BitArray with an infinite array of bits, all on.

◆ bit()

static BitArray bit ( int  index)
static

Returns a BitArray with only the indicated bit on.

◆ clear()

clear ( )

Sets all the bits in the BitArray off.

◆ clearBit()

clearBit ( int  index)

Sets the nth bit off.

If n >= get_num_bits(), this automatically extends the array.

◆ clearRange()

clearRange ( int  low_bit,
int  size 
)

Sets the indicated range of bits off.

◆ compareTo()

int compareTo ( const BitArray  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.

This is based on the same ordering defined by operator <.

◆ extract()

BitArray::WordType 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.

size must be <= get_num_bits_per_word().

◆ getBit()

bool getBit ( int  index)

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.

◆ getClassType()

static TypeHandle getClassType ( )
static

◆ getHighestBits()

bool getHighestBits ( )

Returns true if the infinite set of bits beyond get_num_bits() are all on, or false of they are all off.

◆ getHighestOffBit()

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.

◆ getHighestOnBit()

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.

◆ getLowestOffBit()

int getLowestOffBit ( )

Returns the index of the lowest 0 bit in the array.

Returns -1 if there are no 0 bits.

◆ getLowestOnBit()

int getLowestOnBit ( )

Returns the index of the lowest 1 bit in the array.

Returns -1 if there are no 1 bits.

◆ getMaxNumBits()

static int getMaxNumBits ( )
static

◆ getNextHigherDifferentBit()

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.

◆ getNumBits()

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.

◆ getNumBitsPerWord()

static int getNumBitsPerWord ( )
static

◆ getNumOffBits()

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.

◆ getNumOnBits()

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.

◆ getNumWords()

int getNumWords ( )

Returns the number of possibly-unique words stored in the array.

◆ getWord()

BitArray::MaskType getWord ( int  n)

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.

◆ hasAllOf()

bool hasAllOf ( int  low_bit,
int  size 
)

Returns true if all bits in the indicated range are set, false otherwise.

◆ hasAnyOf()

bool hasAnyOf ( int  low_bit,
int  size 
)

Returns true if any bit in the indicated range is set, false otherwise.

◆ hasBitsInCommon()

bool hasBitsInCommon ( const BitArray  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.

◆ hasMaxNumBits()

static bool hasMaxNumBits ( )
static

◆ invertInPlace()

invertInPlace ( )

Inverts all the bits in the BitArray.

This is equivalent to array = ~array.

◆ isAllOn()

bool isAllOn ( )

Returns true if the entire bitmask is one, false otherwise.

◆ isZero()

bool isZero ( )

Returns true if the entire bitmask is zero, false otherwise.

◆ lowerOn()

static BitArray lowerOn ( int  on_bits)
static

Returns a BitArray whose lower on_bits bits are on.

◆ operator !=()

bool operator != ( const BitArray  other)

◆ operator &()

BitArray operator & ( const BitArray  other)

◆ operator &=()

BitArray operator &= ( const BitArray  other)

◆ operator >>()

BitArray operator >> ( int  shift)

◆ operator >>=()

BitArray operator >>= ( int  shift)

◆ operator ^()

BitArray operator ^ ( const BitArray  other)

◆ operator ^=()

BitArray operator ^= ( const BitArray  other)

◆ operator ~()

BitArray operator ~ ( )

◆ operator<()

bool operator< ( const BitArray  other)

◆ operator<<()

BitArray operator<< ( int  shift)

◆ operator<<=()

BitArray operator<<= ( int  shift)

◆ operator==()

bool operator== ( const BitArray  other)

◆ operator|()

BitArray operator| ( const BitArray  other)

◆ operator|=()

BitArray operator|= ( const BitArray  other)

◆ output()

output ( Ostream  out)

Writes the BitArray out as a hex number.

For a BitArray, this is always the same as output_hex(); it's too confusing for the output format to change back and forth at runtime.

◆ outputBinary()

outputBinary ( Ostream  out,
int  spaces_every 
)

Writes the BitArray out as a binary number, with spaces every four bits.

◆ outputHex()

outputHex ( Ostream  out,
int  spaces_every 
)

Writes the BitArray out as a hexadecimal number, with spaces every four digits.

◆ range()

static BitArray range ( int  low_bit,
int  size 
)
static

Returns a BitArray whose size bits, beginning at low_bit, are on.

◆ setBit()

setBit ( int  index)

Sets the nth bit on.

If n >= get_num_bits(), this automatically extends the array.

◆ setBitTo()

setBitTo ( int  index,
bool  value 
)

Sets the nth bit either on or off, according to the indicated bool value.

◆ setRange()

setRange ( int  low_bit,
int  size 
)

Sets the indicated range of bits on.

◆ setRangeTo()

setRangeTo ( bool  value,
int  low_bit,
int  size 
)

Sets the indicated range of bits to either on or off.

◆ setWord()

setWord ( int  n,
BitArray::WordType  value 
)

Replaces the nth word in the array.

If n >= get_num_words(), this automatically extends the array.

◆ store()

store ( BitArray::WordType  value,
int  low_bit,
int  size 
)

Stores the indicated word into the indicated range of bits with this BitArray.

◆ write()

write ( Ostream  out,
int  indent_level 
)

Writes the BitArray out as a binary or a hex number, according to the number of bits.