Regina Calculation Engine
|
A small but extremely fast "ternary bitmask" class that can store up to 8 * sizeof(T) "trits", each equal to 0, 1 or 2. More...
#include <utilities/ntritmask.h>
Public Member Functions | |
NTritmask1 () | |
Creates a new tritmask with all trits set to 0. More... | |
NTritmask1 (const NTritmask1< T > &cloneMe) | |
Creates a clone of the given tritmask. More... | |
void | reset () |
Sets all trits of this tritmask to 0. More... | |
NTritmask1< T > & | operator= (const NTritmask1< T > &other) |
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... | |
NTritmask1< T > & | minWith (const NTritmask1< T > &rhs) |
Sets this to the minimum of this and the given tritmask. More... | |
NTritmask1< T > & | maxWith (const NTritmask1< T > &rhs) |
Sets this to the maximum of this and the given tritmask. More... | |
NTritmask1< T > & | operator+= (const NTritmask1< T > &rhs) |
Sets this to the sum of this and the given tritmask. More... | |
NTritmask1< T > & | operator-= (const NTritmask1< T > &rhs) |
Sets this to the difference of this and the given tritmask. More... | |
bool | operator== (const NTritmask1< T > &other) const |
Determines whether this and the given tritmask are identical. More... | |
Friends | |
template<typename X > | |
std::ostream & | operator<< (std::ostream &out, const NTritmask1< X > &mask) |
A small but extremely fast "ternary bitmask" class that can store up to 8 * sizeof(T) "trits", each equal to 0, 1 or 2.
This tritmask packs all of the trits together into two variables of type T. This means that operations on 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), where T must be a native unsigned integer type (such as unsigned char, unsigned int, or unsigned long long).
For another extremely fast tritmask class that can store twice as many trits, see NTritmask2. At present there is no tritmask class in Regina that can store arbitrarily many trits.
|
inline |
Creates a new tritmask with all trits set to 0.
|
inline |
Creates a clone of the given tritmask.
cloneMe | the tritmask to clone. |
|
inline |
Determines whether this tritmask contains all zeroes.
true
if every trit is zero, or false
otherwise.
|
inline |
Returns the value of the given trit in this tritmask.
index | indicates which trit to query; this must be between 0 and (8 * sizeof(T) - 1) inclusive. |
|
inline |
Determines whether this tritmask contains at least one trit with value 2.
true
if at least one trit is 2, or false
otherwise.
|
inline |
Sets this to the maximum of this and the given tritmask.
That is, the ith trit will be set to the maximum of the ith trit in this tritmask and the ith trit in other.
This is a "trit" version of boolean OR.
rhs | the tritmask to "max" with this. |
|
inline |
Sets this to the minimum of this and the given tritmask.
That is, the ith trit will be set to the minimum of the ith trit in this tritmask and the ith trit in other.
This is a "trit" version of boolean AND.
rhs | the tritmask to "min" with this. |
|
inline |
Determines whether this tritmask contains at least one non-zero trit.
true
if at least one trit is non-zero, or false
otherwise.
|
inline |
Sets this to the sum of this and the given tritmask.
When adding trits, any digit greater than 2 will simply be replaced with 2. That is:
rhs | the tritmask to add to this. |
|
inline |
Sets this to the difference of this and the given tritmask.
When subtracting trits, any "negative digit" will simply be replaced with zero. That is:
rhs | the tritmask to subtract from this. |
|
inline |
Sets this tritmask to a copy of the given tritmask.
other | the tritmask to clone. |
|
inline |
Determines whether this and the given tritmask are identical.
other | the tritmask to compare against this. |
true
if and only if this and the given tritmask are identical.
|
inline |
Sets all trits of this tritmask to 0.
|
inline |
Sets the given trit of this tritmask to the given value.
index | indicates which trit to set; this must be between 0 and (8 * sizeof(T) - 1) inclusive. |
value | the value that will be assigned to the (index)th trit; this must be 0, 1 or 2. |