40class EXPCL_PANDA_PUTIL BitArray {
42 typedef BitMaskNative MaskType;
43 typedef MaskType::WordType WordType;
46 enum { num_bits_per_word = MaskType::num_bits };
49 INLINE BitArray(WordType init_value);
52 INLINE
static BitArray
all_on();
53 INLINE
static BitArray
all_off();
54 INLINE
static BitArray
lower_on(
int on_bits);
55 INLINE
static BitArray
bit(
int index);
56 INLINE
static BitArray
range(
int low_bit,
int size);
58 constexpr static bool has_max_num_bits() {
return false; }
59 constexpr static int get_max_num_bits() {
return INT_MAX; }
61 constexpr static int get_num_bits_per_word() {
return num_bits_per_word; }
63 INLINE
bool get_bit(
int index)
const;
71 INLINE WordType
extract(
int low_bit,
int size)
const;
72 INLINE
void store(WordType value,
int low_bit,
int size);
77 INLINE
void set_range_to(
bool value,
int low_bit,
int size);
88 INLINE MaskType
get_word(
size_t n)
const;
89 INLINE
void set_word(
size_t n, WordType value);
95 void output(std::ostream &out)
const;
96 void output_binary(std::ostream &out,
int spaces_every = 4)
const;
97 void output_hex(std::ostream &out,
int spaces_every = 4)
const;
98 void write(std::ostream &out,
int indent_level = 0)
const;
100 INLINE
bool operator == (
const BitArray &other)
const;
101 INLINE
bool operator != (
const BitArray &other)
const;
102 INLINE
bool operator < (
const BitArray &other)
const;
106 operator & (
const BitArray &other)
const;
109 operator | (
const BitArray &other)
const;
112 operator ^ (
const BitArray &other)
const;
118 operator << (
int shift)
const;
121 operator >> (
int shift)
const;
123 void operator &= (
const BitArray &other);
124 void operator |= (
const BitArray &other);
125 void operator ^= (
const BitArray &other);
126 void operator <<= (
int shift);
127 void operator >>= (
int shift);
129 EXTENSION(PyObject *__getstate__()
const);
130 EXTENSION(
void __setstate__(PyObject *state));
136 INLINE
void copy_on_write();
137 void ensure_has_word(
int n);
141 typedef PTA(MaskType) Array;
155 static void init_type() {
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
A dynamic array with an unlimited number of bits.
bool get_highest_bits() const
Returns true if the infinite set of bits beyond get_num_bits() are all on, or false of they are all o...
void clear_bit(int index)
Sets the nth bit off.
void output_hex(std::ostream &out, int spaces_every=4) const
Writes the BitArray out as a hexadecimal number, with spaces every four digits.
int get_num_on_bits() const
Returns the number of bits that are set to 1 in the array.
int get_next_higher_different_bit(int low_bit) const
Returns the index of the next bit in the array, above low_bit, whose value is different that the valu...
void set_bit_to(int index, bool value)
Sets the nth bit either on or off, according to the indicated bool value.
void set_word(size_t n, WordType value)
Replaces the nth word in the array.
MaskType get_word(size_t n) const
Returns the nth word in the array.
bool has_any_of(int low_bit, int size) const
Returns true if any bit in the indicated range is set, false otherwise.
int compare_to(const BitArray &other) const
Returns a number less than zero if this BitArray sorts before the indicated other BitArray,...
static BitArray all_off()
Returns a BitArray whose bits are all off.
int get_highest_off_bit() const
Returns the index of the highest 0 bit in the array.
void generate_hash(ChecksumHashGenerator &hashgen) const
Adds the bitmask to the indicated hash generator.
void invert_in_place()
Inverts all the bits in the BitArray.
bool has_all_of(int low_bit, int size) const
Returns true if all bits in the indicated range are set, false otherwise.
int get_lowest_off_bit() const
Returns the index of the lowest 0 bit in the array.
void read_datagram(DatagramIterator &scan, BamReader *manager)
Reads the object that was previously written to a Bam file.
size_t get_num_bits() const
Returns the current number of possibly different bits in this array.
static BitArray lower_on(int on_bits)
Returns a BitArray whose lower on_bits bits are on.
void output(std::ostream &out) const
Writes the BitArray out as a hex number.
void set_range(int low_bit, int size)
Sets the indicated range of bits on.
void clear()
Sets all the bits in the BitArray off.
bool has_bits_in_common(const BitArray &other) const
Returns true if this BitArray has any "one" bits in common with the other one, false otherwise.
static BitArray range(int low_bit, int size)
Returns a BitArray whose size bits, beginning at low_bit, are on.
void set_bit(int index)
Sets the nth bit on.
static BitArray all_on()
Returns a BitArray with an infinite array of bits, all on.
WordType extract(int low_bit, int size) const
Returns a word that represents only the indicated range of bits within this BitArray,...
void write_datagram(BamWriter *manager, Datagram &dg) const
Writes the contents of this object to the datagram for shipping out to a Bam file.
int get_num_off_bits() const
Returns the number of bits that are set to 0 in the array.
void store(WordType value, int low_bit, int size)
Stores the indicated word into the indicated range of bits with this BitArray.
void output_binary(std::ostream &out, int spaces_every=4) const
Writes the BitArray out as a binary number, with spaces every four bits.
bool is_zero() const
Returns true if the entire bitmask is zero, false otherwise.
bool get_bit(int index) const
Returns true if the nth bit is set, false if it is cleared.
void set_range_to(bool value, int low_bit, int size)
Sets the indicated range of bits to either on or off.
static BitArray bit(int index)
Returns a BitArray with only the indicated bit on.
void write(std::ostream &out, int indent_level=0) const
Writes the BitArray out as a binary or a hex number, according to the number of bits.
void clear_range(int low_bit, int size)
Sets the indicated range of bits off.
size_t get_num_words() const
Returns the number of possibly-unique words stored in the array.
bool is_all_on() const
Returns true if the entire bitmask is one, false otherwise.
This is a specific kind of HashGenerator that simply adds up all of the ints.
A class to retrieve the individual data elements previously stored in a Datagram.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
The default class template does not define any methods.
This class records a set of integers, where each integer is either present or not present in the set.
TypeHandle is the identifier used to differentiate C++ class types.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int get_highest_on_bit(unsigned short x)
Returns the index of the highest 1 bit in the word.
int get_lowest_on_bit(unsigned short x)
Returns the index of the lowest 1 bit in the word.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.