RE/flex Bits class for dynamic bit vectors. More...
#include <bits.h>
Classes | |
| struct | Bitref |
| References a single bit, returned by operator[]. More... | |
Public Member Functions | |
| Bits () | |
| Construct an empty bit vector. More... | |
| Bits (const Bits &bits) | |
| Copy constructor. More... | |
| Bits (size_t n) | |
| Construct a bit vector and set n'th bit. More... | |
| Bits (size_t n1, size_t n2) | |
| Construct a bit vector and set a range of bits n1'th to n2'th. More... | |
| ~Bits () | |
| Destroy bits. More... | |
| Bits & | operator= (const Bits &bits) |
| Assign bits. More... | |
| Bitref | operator[] (size_t n) |
| Reference n'th bit in the bit vector to assign a value to that bit. More... | |
| bool | operator[] (size_t n) const |
| Returns n'th bit. More... | |
| Bits & | insert (size_t n) |
| Insert and set a bit in the bit vector. More... | |
| Bits & | erase (size_t n) |
| Erase a bit in the bit vector. More... | |
| Bits & | flip (size_t n) |
| Flips a bit in the bit vector. More... | |
| Bits & | insert (size_t n1, size_t n2) |
| Insert and set a range of bits in the bit vector. More... | |
| Bits & | erase (size_t n1, size_t n2) |
| Erase a range of bits in the bit vector. More... | |
| Bits & | flip (size_t n1, size_t n2) |
| Flip a range of bits in the bit vector. More... | |
| Bits & | lshift () |
| Bit-shift left by one. More... | |
| Bits & | rshift () |
| Bit-shift right by one. More... | |
| Bits & | operator|= (const Bits &bits) |
| Bit-or (set union) the bit vector with the given bits. More... | |
| Bits & | operator&= (const Bits &bits) |
| Bit-and (set intersection) the bit vector with the given bits. More... | |
| Bits & | operator^= (const Bits &bits) |
| Bit-xor the bit vector with the given bits. More... | |
| Bits & | operator-= (const Bits &bits) |
| Bit-delete (set minus) the bit vector with the given bits. More... | |
| Bits | operator| (const Bits &bits) const |
| Bit-or (set union) of two bit vectors. More... | |
| Bits | operator& (const Bits &bits) const |
| Bit-and (set intersection) of two bit vectors. More... | |
| Bits | operator^ (const Bits &bits) const |
| Bit-xor of two bit vectors. More... | |
| Bits | operator- (const Bits &bits) const |
| Bit-delete (set minus) of two bit vectors. More... | |
| Bits | operator~ () const |
| Complement of the bit vector with all bits flipped. More... | |
| bool | operator== (const Bits &bits) const |
| Returns true if bit vectors are equal. More... | |
| bool | operator!= (const Bits &bits) const |
| Returns true if bit vectors are unequal. More... | |
| bool | operator< (const Bits &bits) const |
| Returns true if the bit vector is lexicographically less than the given right-hand side bits. More... | |
| bool | operator> (const Bits &bits) const |
| Returns true if the bit vector is lexicographically greater than the given right-hand side bits. More... | |
| bool | operator<= (const Bits &bits) const |
| Returns true if the bit vector is lexicographically less-or-equal to the given right-hand side bits. More... | |
| bool | operator>= (const Bits &bits) const |
| Returns true if the bit vector is lexicographically greater-or-equal to the given right-hand side bits. More... | |
| bool | all () const |
| Returns true if all bits are set. More... | |
| bool | any () const |
| Returns true if any bit is set. More... | |
| Bits & | clear () |
| Erase all bits. More... | |
| Bits & | flip () |
| Flip all bits. More... | |
| Bits & | reserve (size_t len) |
| Reserves space in the bit vector for len bits without changing its current content. More... | |
| size_t | size () const |
| Returns the current length of the bit vector. More... | |
| size_t | count () const |
| Returns the number of bits set. More... | |
| bool | intersects (const Bits &bits) const |
| Returns true if the bit vector intersects with the given bits, false if the bit vectors are disjoint. More... | |
| bool | contains (const Bits &bits) const |
| Returns true if the given bits are a subset of the bit vector, i.e. for each bit in bits, the corresponding bit in the bit vector is set. More... | |
| size_t | find_first (size_t n=0) const |
| Returns the position of the first bit set in the bit vector, or Bits::npos if none. More... | |
| size_t | find_next (size_t n) const |
| Returns the next position of a bit set in the bit vector, or Bits::npos if none. More... | |
| void | swap (Bits &bits) |
| Swap bit vectors. More... | |
Static Public Attributes | |
| static const size_t | npos = static_cast<size_t>(-1) |
Private Member Functions | |
| void | alloc (size_t len) |
| On-demand allocator. More... | |
Private Attributes | |
| size_t | len_ |
| number of words More... | |
| uint64_t * | vec_ |
| array of words More... | |
RE/flex Bits class for dynamic bit vectors.
Dynamic bit vectors are stored in Bits objects, which can be manipulated with the usual bit-operations (| (bitor), & (bitand), ^ (bitxor)). Supports comparison relations on bit vectors, check if all bits set, check if any bits are set, flip bits, shift bits left or right, count bits, check if a bit vectors intersects another, check if a bit vector contains another. find_first bit, find_next bit.
Example:
Output:
upper and lower are disjoint digit is a subset of alnum _ is not in alnum _ is in updated alnum 63 bits in alnum 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz
|
inline |
Construct an empty bit vector.
|
inline |
Copy constructor.
| bits | bits to copy |
|
inline |
Construct a bit vector and set n'th bit.
| n | n'th bit to set |
|
inline |
Construct a bit vector and set a range of bits n1'th to n2'th.
| n1 | first bit to set |
| n2 | last bit to set |
|
inline |
Destroy bits.
|
inline |
Returns true if all bits are set.
|
inlineprivate |
On-demand allocator.
| len | number of words required |
|
inline |
Returns true if any bit is set.
|
inline |
Erase all bits.
|
inline |
Returns true if the given bits are a subset of the bit vector, i.e. for each bit in bits, the corresponding bit in the bit vector is set.
| bits | bits |
|
inline |
Returns the number of bits set.
|
inline |
Erase a bit in the bit vector.
| n | n'th bit to erase |
|
inline |
Erase a range of bits in the bit vector.
| n1 | first bit to erase |
| n2 | last bit to erase |
|
inline |
Returns the position of the first bit set in the bit vector, or Bits::npos if none.
| n | internal parameter (do not use) |
|
inline |
Returns the next position of a bit set in the bit vector, or Bits::npos if none.
| n | the current position to search from |
|
inline |
Flips a bit in the bit vector.
| n | n'th bit to flip |
|
inline |
Flip a range of bits in the bit vector.
| n1 | first bit to flip |
| n2 | last bit to flip |
|
inline |
Flip all bits.
|
inline |
Insert and set a bit in the bit vector.
| n | n'th bit to set |
|
inline |
Insert and set a range of bits in the bit vector.
| n1 | first bit to set |
| n2 | last bit to set |
|
inline |
Returns true if the bit vector intersects with the given bits, false if the bit vectors are disjoint.
| bits | bits |
|
inline |
Bit-shift left by one.
|
inline |
Returns true if bit vectors are unequal.
| bits | rhs bits |
Bit-and (set intersection) of two bit vectors.
| bits | bits |
Bit-and (set intersection) the bit vector with the given bits.
| bits | bits |
Bit-delete (set minus) of two bit vectors.
| bits | bits |
Bit-delete (set minus) the bit vector with the given bits.
| bits | bits |
|
inline |
Returns true if the bit vector is lexicographically less than the given right-hand side bits.
| bits | rhs bits |
|
inline |
Returns true if the bit vector is lexicographically less-or-equal to the given right-hand side bits.
| bits | rhs bits |
Assign bits.
| bits | bits to copy |
|
inline |
Returns true if bit vectors are equal.
| bits | rhs bits |
|
inline |
Returns true if the bit vector is lexicographically greater than the given right-hand side bits.
| bits | rhs bits |
|
inline |
Returns true if the bit vector is lexicographically greater-or-equal to the given right-hand side bits.
| bits | rhs bits |
|
inline |
Reference n'th bit in the bit vector to assign a value to that bit.
| n | n'th bit |
|
inline |
Returns n'th bit.
| n | n'th bit to return |
Bit-xor of two bit vectors.
| bits | bits |
Bit-xor the bit vector with the given bits.
| bits | bits |
Bit-or (set union) of two bit vectors.
| bits | bits |
Bit-or (set union) the bit vector with the given bits.
| bits | bits |
|
inline |
Complement of the bit vector with all bits flipped.
|
inline |
Reserves space in the bit vector for len bits without changing its current content.
| len | number of bits to reserve |
|
inline |
Bit-shift right by one.
|
inline |
Returns the current length of the bit vector.
|
inline |
Swap bit vectors.
| bits | bits |
|
private |
number of words
|
static |
npos returned by find_first() and find_next()
|
private |
array of words