|
Click
|
#include <bitvector.hh>
Classes | |
| class | Bit |
| A wrapper class that acts like a single bit. More... | |
Public Types | |
| enum | { wbits = 32 , wshift = 5 , wmask = 31 } |
| typedef bool(Bitvector::* | unspecified_bool_type) () const |
| typedef uint32_t | word_type |
Public Member Functions | |
| Bitvector () | |
| Construct an empty bitvector. | |
| Bitvector (int n) | |
| Construct an all-false bitvector with n elements. | |
| Bitvector (bool bit) | |
| Construct a bit-valued length-1 bitvector. | |
| Bitvector (int n, bool bit) | |
| Construct a bit-valued length-n bitvector. | |
| Bitvector (const Bitvector &x) | |
| Construct a bitvector as a copy of x. | |
| ~Bitvector () | |
| Destroy a bitvector. | |
| int | size () const |
| Return the number of bits in the bitvector. | |
| Bit | operator[] (int i) |
| Return the bit at position i. | |
| bool | operator[] (int i) const |
| Bit | force_bit (int i) |
| Return the bit at position i, extending if necessary. | |
| int | word_size () const |
| Return the number of valid data words. | |
| int | max_word () const |
| Return the index of the maximum valid data word. | |
| word_type * | words () |
| Return a pointer to this bitvector's data words. | |
| const word_type * | words () const |
| bool | zero () const |
| Test if the bitvector's bits are all false. | |
| operator unspecified_bool_type () const | |
| Test if the bitvector contains at least one true bit. | |
| bool | operator! () const |
| Test if the bitvector contains no true bits. | |
| Bitvector & | assign (int n, bool bit) |
| Set the bitvector to bit-valued length-n. | |
| Bitvector & | operator= (const Bitvector &x) |
| Set this bitvector to a copy of x. | |
| void | clear () |
| Set all bits to false. | |
| void | resize (int n) |
| Resize the bitvector to n bits. | |
| bool | nonzero_intersection (const Bitvector &x) const |
| Test whether this bitvector and x have a common true bit. | |
| Bitvector | operator~ () const |
| Return the bitwise negation of this bitvector. | |
| void | flip () |
| Flip all bits in this bitvector. | |
| void | negate () |
| Flip all bits in this bitvector. | |
| Bitvector & | operator&= (const Bitvector &x) |
| Modify this bitvector by bitwise and with x. | |
| Bitvector & | operator|= (const Bitvector &x) |
| Modify this bitvector by bitwise or with x. | |
| Bitvector & | operator^= (const Bitvector &x) |
| Modify this bitvector by bitwise exclusive or with x. | |
| Bitvector & | operator-= (const Bitvector &x) |
| Modify this bitvector by bitwise subtraction with x. | |
| void | offset_or (const Bitvector &x, int offset) |
| Modify this bitvector by bitwise or with an offset x. | |
| void | or_with_difference (const Bitvector &x, Bitvector &difference) |
| Modify this bitvector by bitwise or, returning difference. | |
| void | swap (Bitvector &x) |
| Swap the contents of this bitvector and x. | |
| void | set_range (int start, int length, bool value) |
| bool | range (int start, int length) |
| int | weight () const |
| Return the number of true bits. | |
| int | popcnt () const |
| Return the number of true bits. | |
| int | weight_range (int start, int length) const |
| Return the number of true bits. | |
| int | clz () const |
| Return the number of leading zeroes. | |
| bool | parse (const String &str, int min_val, int max_val, int offset=0) |
| String | unparse (int read_offset=0, int output_offset=0) const |
Static Public Member Functions | |
| static Bitvector | from_mask (unsigned long mask) |
Vector of bits.
The Bitvector class implements a vector of individually addressable bits. It supports bitwise operations such as |= and &= as well as the usual assignment and indexing operations.
Bitvectors are stored as arrays of data words with type word_type, each containing wbits bits. For some purposes it may be faster or easier to manipulate data words directly.
|
inline |
Construct an empty bitvector.
|
inlineexplicit |
Construct an all-false bitvector with n elements.
|
inlineexplicit |
Construct a bit-valued length-1 bitvector.
|
inline |
Construct a bit-valued length-n bitvector.
|
inline |
Construct a bitvector as a copy of x.
|
inline |
Destroy a bitvector.
All outstanding Bit objects become invalid.
|
inline |
Return the number of bits in the bitvector.
|
inline |
Return the bit at position i.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
inline |
|
inline |
Return the number of valid data words.
|
inline |
Return the index of the maximum valid data word.
|
inline |
Return a pointer to this bitvector's data words.
|
inline |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
| bool Bitvector::zero | ( | ) | const |
Test if the bitvector's bits are all false.
|
inline |
Test if the bitvector contains at least one true bit.
|
inline |
Test if the bitvector contains no true bits.
| Bitvector & Bitvector::assign | ( | int | n, |
| bool | bit | ||
| ) |
Set the bitvector to bit-valued length-n.
Set this bitvector to a copy of x.
| void Bitvector::clear | ( | ) |
Set all bits to false.
| void Bitvector::resize | ( | int | n | ) |
Resize the bitvector to n bits.
Any bits added to the bitvector are false.
| bool Bitvector::nonzero_intersection | ( | const Bitvector & | x | ) | const |
Test whether this bitvector and x have a common true bit.
This bitvector and x may have different sizes.
|
inline |
Return the bitwise negation of this bitvector.
| void Bitvector::flip | ( | ) |
Flip all bits in this bitvector.
|
inline |
Flip all bits in this bitvector.
Modify this bitvector by bitwise subtraction with x.
Equivalent to *this &= ~x.
| void Bitvector::offset_or | ( | const Bitvector & | x, |
| int | offset | ||
| ) |
Modify this bitvector by bitwise or with an offset x.
| x | bitwise or operand |
| offset | initial offset |
Logically shifts x to start at position offset, then performs a bitwise or. a.offset_or(b, offset) is equivalent to:
Modify this bitvector by bitwise or, returning difference.
| x | bitwise or operand | |
| [out] | difference | set to (x - old *this) |
Same as operator|=, but any newly set bits are returned in difference.
| void Bitvector::swap | ( | Bitvector & | x | ) |
Swap the contents of this bitvector and x.
|
inline |
Return the number of true bits.
|
inline |
Return the number of true bits.
|
inline |
Return the number of true bits.
|
inline |
Return the number of leading zeroes.
|
static |
never