Regina Calculation Engine
Public Member Functions | Friends | List of all members
regina::NTritmask2< T, U > Class Template Reference

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/ntritmask.h>

Public Member Functions

 NTritmask2 ()
 Creates a new tritmask with all trits set to 0. More...
 
 NTritmask2 (const NTritmask2< T, U > &cloneMe)
 Creates a clone of the given tritmask. More...
 
void reset ()
 Sets all trits of this tritmask to 0. More...
 
NTritmask2< T, U > & operator= (const NTritmask2< T, U > &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...
 
NTritmask2< T, U > & minWith (const NTritmask2< T, U > &rhs)
 Sets this to the minimum of this and the given tritmask. More...
 
NTritmask2< T, U > & maxWith (const NTritmask2< T, U > &rhs)
 Sets this to the maximum of this and the given tritmask. More...
 
NTritmask2< T, U > & operator+= (const NTritmask2< T, U > &rhs)
 Sets this to the sum of this and the given tritmask. More...
 
NTritmask2< T, U > & operator-= (const NTritmask2< T, U > &rhs)
 Sets this to the difference of this and the given tritmask. More...
 
bool operator== (const NTritmask2< T, U > &other) const
 Determines whether this and the given tritmask are identical. More...
 

Friends

template<typename X , typename Y >
std::ostream & operator<< (std::ostream &out, const NTritmask2< X, Y > &mask)
 

Detailed Description

template<typename T, typename U = T>
class regina::NTritmask2< T, U >

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 NTritmask1. At present there is no tritmask class in Regina that can store arbitrarily many trits.

Precondition
Types T and U are unsigned integral numeric types.
Python:
Not present.

Constructor & Destructor Documentation

template<typename T , typename U = T>
regina::NTritmask2< T, U >::NTritmask2 ( )
inline

Creates a new tritmask with all trits set to 0.

template<typename T , typename U = T>
regina::NTritmask2< T, U >::NTritmask2 ( const NTritmask2< T, U > &  cloneMe)
inline

Creates a clone of the given tritmask.

Parameters
cloneMethe tritmask to clone.

Member Function Documentation

template<typename T , typename U = T>
bool regina::NTritmask2< T, U >::empty ( ) const
inline

Determines whether this tritmask contains all zeroes.

Returns
true if every trit is zero, or false otherwise.
template<typename T , typename U = T>
char regina::NTritmask2< T, U >::get ( unsigned  index) const
inline

Returns the value of the given trit in this tritmask.

Parameters
indexindicates which trit to query; this must be between 0 and (8 * sizeof(T) + 8 * sizeof(U) - 1) inclusive.
Returns
the value of the (index)th trit; this will be either 0, 1 or 2.
template<typename T , typename U = T>
bool regina::NTritmask2< T, U >::has2 ( ) const
inline

Determines whether this tritmask contains at least one trit with value 2.

Returns
true if at least one trit is 2, or false otherwise.
template<typename T , typename U = T>
NTritmask2<T, U>& regina::NTritmask2< T, U >::maxWith ( const NTritmask2< T, U > &  rhs)
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.

Parameters
rhsthe tritmask to "max" with this.
Returns
a reference to this tritmask.
template<typename T , typename U = T>
NTritmask2<T, U>& regina::NTritmask2< T, U >::minWith ( const NTritmask2< T, U > &  rhs)
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.

Parameters
rhsthe tritmask to "min" with this.
Returns
a reference to this tritmask.
template<typename T , typename U = T>
bool regina::NTritmask2< T, U >::nonEmpty ( ) const
inline

Determines whether this tritmask contains at least one non-zero trit.

Returns
true if at least one trit is non-zero, or false otherwise.
template<typename T , typename U = T>
NTritmask2<T, U>& regina::NTritmask2< T, U >::operator+= ( const NTritmask2< T, U > &  rhs)
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:

  • 2+2 = 1+2 = 1+1 = 2;
  • 0+x = x for any x.
Parameters
rhsthe tritmask to add to this.
Returns
a reference to this tritmask.
template<typename T , typename U = T>
NTritmask2<T, U>& regina::NTritmask2< T, U >::operator-= ( const NTritmask2< T, U > &  rhs)
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:

  • 2-0 = 2, 2-1 = 1, and 2-2 = 0;
  • 1-0 = 1, and 1-1 = 1-2 = 0;
  • 0-x = 0 for any x.
Parameters
rhsthe tritmask to subtract from this.
Returns
a reference to this tritmask.
template<typename T , typename U = T>
NTritmask2<T, U>& regina::NTritmask2< T, U >::operator= ( const NTritmask2< T, U > &  other)
inline

Sets this tritmask to a copy of the given tritmask.

Parameters
otherthe tritmask to clone.
Returns
a reference to this tritmask.
template<typename T , typename U = T>
bool regina::NTritmask2< T, U >::operator== ( const NTritmask2< T, U > &  other) const
inline

Determines whether this and the given tritmask are identical.

Parameters
otherthe tritmask to compare against this.
Returns
true if and only if this and the given tritmask are identical.
template<typename T , typename U = T>
void regina::NTritmask2< T, U >::reset ( )
inline

Sets all trits of this tritmask to 0.

template<typename T , typename U = T>
void regina::NTritmask2< T, U >::set ( unsigned  index,
char  value 
)
inline

Sets the given trit of this tritmask to the given value.

Parameters
indexindicates which trit to set; this must be between 0 and (8 * sizeof(T) + 8 * sizeof(U) - 1) inclusive.
valuethe value that will be assigned to the (index)th trit; this must be 0, 1 or 2.

The documentation for this class was generated from the following file:

Copyright © 1999-2014, The Regina development team
This software is released under the GNU General Public License, with some additional permissions; see the source code for details.
For further information, or to submit a bug or other problem, please contact Ben Burton (bab@debian.org).