Regina Calculation Engine
|
A small but extremely fast "ternary bitmask" class that can store up to 8 * sizeof(T) + 8 * sizeof(U) "trits", each equal to 0, 1 or 2. More...
#include <utilities/tritmask.h>
Public Member Functions | |
Tritmask2 () | |
Creates a new tritmask with all trits set to 0. More... | |
Tritmask2 (const Tritmask2< T, U > &cloneMe)=default | |
Creates a clone of the given tritmask. More... | |
void | reset () |
Sets all trits of this tritmask to 0. More... | |
Tritmask2< T, U > & | operator= (const Tritmask2< T, U > &other)=default |
Sets this tritmask to a copy of the given tritmask. More... | |
char | get (unsigned index) const |
Returns the value of the given trit in this tritmask. More... | |
void | set (unsigned index, char value) |
Sets the given trit of this tritmask to the given value. More... | |
bool | empty () const |
Determines whether this tritmask contains all zeroes. More... | |
bool | nonEmpty () const |
Determines whether this tritmask contains at least one non-zero trit. More... | |
bool | has2 () const |
Determines whether this tritmask contains at least one trit with value 2. More... | |
Tritmask2< T, U > & | minWith (const Tritmask2< T, U > &rhs) |
Sets this to the minimum of this and the given tritmask. More... | |
Tritmask2< T, U > & | maxWith (const Tritmask2< T, U > &rhs) |
Sets this to the maximum of this and the given tritmask. More... | |
Tritmask2< T, U > & | operator+= (const Tritmask2< T, U > &rhs) |
Sets this to the sum of this and the given tritmask. More... | |
Tritmask2< T, U > & | operator-= (const Tritmask2< T, U > &rhs) |
Sets this to the difference of this and the given tritmask. More... | |
bool | operator== (const Tritmask2< T, U > &other) const |
Determines whether this and the given tritmask are identical. More... | |
Friends | |
std::ostream & | operator<< (std::ostream &out, const Tritmask2< T, U > &mask) |
Writes the given tritmask to the given output stream as a sequence of digits (0, 1 and/or 2). More... | |
A small but extremely fast "ternary bitmask" class that can store up to 8 * sizeof(T) + 8 * sizeof(U) "trits", each equal to 0, 1 or 2.
This tritmask packs all of the trits together into two variables of type T and two variables of type U. This means that operations on entire tritmasks are extremely fast, because all of the trits can be processed in just a few native CPU operations.
The downside of course is that the number of trits that can be stored is limited to 8 * sizeof(T) + 8 * sizeof(U), where T and U must be native unsigned integer types (such as unsigned char, unsigned int, or unsigned long long).
For an even faster tritmask class that can only store half as many trits, see Tritmask1. At present there is no tritmask class in Regina that can store arbitrarily many trits.