Regina Calculation Engine
|
A small but extremely fast bitmask class that can store up to 8 * sizeof(T) true-or-false bits. More...
#include <utilities/bitmask.h>
Public Member Functions | |
Bitmask1 () | |
Creates a new bitmask with all bits set to false . More... | |
Bitmask1 (size_t) | |
Creates a new bitmask with all bits set to false . More... | |
Bitmask1 (const Bitmask1< T > &cloneMe)=default | |
Creates a clone of the given bitmask. More... | |
void | reset () |
Sets all bits of this bitmask to false . More... | |
void | reset (size_t) |
Sets all bits of this bitmask to false . More... | |
Bitmask1< T > & | operator= (const Bitmask1< T > &other)=default |
Sets this bitmask to a copy of the given bitmask. More... | |
void | truncate (size_t numBits) |
Leaves the first numBits bits of this bitmask intact, but sets all subsequent bits to false . More... | |
bool | get (size_t index) const |
Returns the value of the given bit of this bitmask. More... | |
void | set (size_t index, bool value) |
Sets the given bit of this bitmask to the given value. More... | |
template<typename ForwardIterator > | |
void | set (ForwardIterator indexBegin, ForwardIterator indexEnd, bool value) |
Sets all bits in the given sorted list to the given value. More... | |
Bitmask1< T > & | operator&= (const Bitmask1< T > &other) |
Sets this to the intersection of this and the given bitmask. More... | |
Bitmask1< T > & | operator|= (const Bitmask1< T > &other) |
Sets this to the union of this and the given bitmask. More... | |
Bitmask1< T > & | operator^= (const Bitmask1< T > &other) |
Sets this to the exclusive disjunction (XOR) of this and the given bitmask. More... | |
Bitmask1< T > & | operator-= (const Bitmask1< T > &other) |
Sets this to the set difference of this and the given bitmask. More... | |
void | flip () |
Negates every bit in this bitmask. More... | |
bool | operator== (const Bitmask1< T > &other) const |
Determines whether this and the given bitmask are identical. More... | |
bool | lessThan (const Bitmask1< T > &other) const |
Determines whether this bitmask appears strictly before the given bitmask when bitmasks are sorted in lexicographical order. More... | |
bool | operator<= (const Bitmask1< T > &other) const |
Determines whether this bitmask is entirely contained within the given bitmask. More... | |
bool | inUnion (const Bitmask1< T > &x, const Bitmask1< T > &y) const |
Determines whether this bitmask is entirely contained within the union of the two given bitmasks. More... | |
bool | containsIntn (const Bitmask1< T > &x, const Bitmask1< T > &y) const |
Determines whether this bitmask contains the intersection of the two given bitmasks. More... | |
size_t | bits () const |
Returns the number of bits currently set to true in this bitmask. More... | |
long | firstBit () const |
Returns the index of the first true bit in this bitmask, or -1 if there are no true bits. More... | |
long | lastBit () const |
Returns the index of the last true bit in this bitmask, or -1 if there are no true bits. More... | |
bool | atMostOneBit () const |
Determines whether at most one bit is set to true in this bitmask. More... | |
Friends | |
std::ostream & | operator (std::ostream &out, const Bitmask1< T > &mask) |
A small but extremely fast bitmask class that can store up to 8 * sizeof(T) true-or-false bits.
This bitmask packs all of the bits together into a single variable of type T. This means that operations on bitmasks are extremely fast, because all of the bits can be processed at once.
The downside of course is that the number of bits that can be stored is limited to 8 * sizeof(T), where T must be a native unsigned integer type (such as unsigned char, unsigned int, or unsigned long long).
For another extremely fast bitmask class that can store twice as many bits, see Bitmask2. For a bitmask class that can store arbitrarily many bits, see Bitmask.