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

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)
 

Detailed Description

template<typename T>
class regina::NTritmask1< T >

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.

Precondition
Type T is an unsigned integral numeric type.
Python:
Not present.

Constructor & Destructor Documentation

template<typename T >
regina::NTritmask1< T >::NTritmask1 ( )
inline

Creates a new tritmask with all trits set to 0.

template<typename T >
regina::NTritmask1< T >::NTritmask1 ( const NTritmask1< T > &  cloneMe)
inline

Creates a clone of the given tritmask.

Parameters
cloneMethe tritmask to clone.

Member Function Documentation

template<typename T >
bool regina::NTritmask1< T >::empty ( ) const
inline

Determines whether this tritmask contains all zeroes.

Returns
true if every trit is zero, or false otherwise.
template<typename T >
char regina::NTritmask1< T >::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) - 1) inclusive.
Returns
the value of the (index)th trit; this will be either 0, 1 or 2.
template<typename T >
bool regina::NTritmask1< T >::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 >
NTritmask1<T>& regina::NTritmask1< T >::maxWith ( const NTritmask1< T > &  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 >
NTritmask1<T>& regina::NTritmask1< T >::minWith ( const NTritmask1< T > &  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 >
bool regina::NTritmask1< T >::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 >
NTritmask1<T>& regina::NTritmask1< T >::operator+= ( const NTritmask1< T > &  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 >
NTritmask1<T>& regina::NTritmask1< T >::operator-= ( const NTritmask1< T > &  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 >
NTritmask1<T>& regina::NTritmask1< T >::operator= ( const NTritmask1< T > &  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 >
bool regina::NTritmask1< T >::operator== ( const NTritmask1< T > &  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 >
void regina::NTritmask1< T >::reset ( )
inline

Sets all trits of this tritmask to 0.

template<typename T >
void regina::NTritmask1< T >::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) - 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).