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

A small but extremely fast "base 4 bitmask" class that can store up to 8 * sizeof(T) + 8 * sizeof(U) "qits", each equal to 0, 1, 2 or 3. More...

#include <utilities/qitmask.h>

Public Member Functions

 Qitmask2 ()
 Creates a new qitmask with all qits set to 0. More...
 
 Qitmask2 (const Qitmask2< T, U > &cloneMe)=default
 Creates a clone of the given qitmask. More...
 
void reset ()
 Sets all qits of this qitmask to 0. More...
 
Qitmask2< T, U > & operator= (const Qitmask2< T, U > &other)=default
 Sets this qitmask to a copy of the given qitmask. More...
 
uint8_t get (unsigned index) const
 Returns the value of the given qit in this qitmask. More...
 
void set (unsigned index, uint8_t value)
 Sets the given qit of this qitmask to the given value. More...
 
bool empty () const
 Determines whether this qitmask contains all zeroes. More...
 
bool nonEmpty () const
 Determines whether this qitmask contains at least one non-zero qit. More...
 
bool has3 () const
 Determines whether this qitmask contains at least one qit with value 3. More...
 
Qitmask2< T, U > & operator+= (const Qitmask2< T, U > &rhs)
 Sets this to the sum of this and the given qitmask. More...
 
Qitmask2< T, U > & operator-= (const Qitmask2< T, U > &rhs)
 Sets this to the difference of this and the given qitmask. More...
 
bool operator== (const Qitmask2< T, U > &other) const
 Determines whether this and the given qitmask are identical. More...
 
bool operator!= (const Qitmask2< T, U > &other) const
 Determines whether this and the given qitmask are different. More...
 
bool hasNonZeroMatch (const Qitmask2< T, U > &other) const
 Determines whether there is some index at which both this and the given qitmask both have non-zero qits. More...
 

Friends

std::ostream & operator (std::ostream &out, const Qitmask2< T, U > &mask)
 

Detailed Description

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

A small but extremely fast "base 4 bitmask" class that can store up to 8 * sizeof(T) + 8 * sizeof(U) "qits", each equal to 0, 1, 2 or 3.

This qitmask packs all of the qits together into two variables of type T and two variables of type U. This means that operations on entire qitmasks are extremely fast, because all of the qits can be processed in just a few native CPU operations.

The downside of course is that the number of qits 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 qitmask class that can only store half as many qits, see Qitmask1. At present there is no qitmask class in Regina that can store arbitrarily many qits.

These objects are small enough to pass by value and swap with std::swap(), with no need for any specialised move operations or swap functions.

Precondition
Types T and U are unsigned integral numeric types.
Python
Python does not support templates, and so instead Regina's python interface offers the classes Qitmask8, Qitmask16, Qitmask32, Qitmask64, Qitmask128, and (if the machine supports 128-bit integers) Qitmask256. Each of these will be an optimised qitmask class that can hold the corresponding number of bits, and is guaranteed to be an instance of either the C++ Qitmask1<T> class (where possible) or the C++ Qitmask2<T,U> template class (if necessary).

Constructor & Destructor Documentation

◆ Qitmask2() [1/2]

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

Creates a new qitmask with all qits set to 0.

◆ Qitmask2() [2/2]

template<typename T , typename U = T>
regina::Qitmask2< T, U >::Qitmask2 ( const Qitmask2< T, U > &  cloneMe)
inlinedefault

Creates a clone of the given qitmask.

Parameters
cloneMethe qitmask to clone.

Member Function Documentation

◆ empty()

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

Determines whether this qitmask contains all zeroes.

Returns
true if every qit is zero, or false otherwise.

◆ get()

template<typename T , typename U = T>
uint8_t regina::Qitmask2< T, U >::get ( unsigned  index) const
inline

Returns the value of the given qit in this qitmask.

Parameters
indexindicates which qit to query; this must be between 0 and (8 * sizeof(T) + 8 * sizeof(U) - 1) inclusive.
Returns
the value of the (index)th qit; this will be either 0, 1, 2 or 3.

◆ has3()

template<typename T , typename U = T>
bool regina::Qitmask2< T, U >::has3 ( ) const
inline

Determines whether this qitmask contains at least one qit with value 3.

Returns
true if at least one qit is 3, or false otherwise.

◆ hasNonZeroMatch()

template<typename T , typename U = T>
bool regina::Qitmask2< T, U >::hasNonZeroMatch ( const Qitmask2< T, U > &  other) const
inline

Determines whether there is some index at which both this and the given qitmask both have non-zero qits.

That is, there is some index i for which get(i) and other.get(i) are both non-zero.

Note that these two qits do not need to be equal; they just both need to be non-zero. Note also that this only needs to happen at one index; there may be other indices at which the qit is zero in one qitmask but not the other.

Parameters
otherthe qitmask to compare with this.
Returns
true if there is some index at which this and other both have non-zero qits, or false otherwise.

◆ nonEmpty()

template<typename T , typename U = T>
bool regina::Qitmask2< T, U >::nonEmpty ( ) const
inline

Determines whether this qitmask contains at least one non-zero qit.

Returns
true if at least one qit is non-zero, or false otherwise.

◆ operator!=()

template<typename T , typename U = T>
bool regina::Qitmask2< T, U >::operator!= ( const Qitmask2< T, U > &  other) const
inline

Determines whether this and the given qitmask are different.

Parameters
otherthe qitmask to compare against this.
Returns
true if and only if this and the given qitmask are different.

◆ operator+=()

template<typename T , typename U = T>
Qitmask2< T, U > & regina::Qitmask2< T, U >::operator+= ( const Qitmask2< T, U > &  rhs)
inline

Sets this to the sum of this and the given qitmask.

Each pair of qits is added modulo 4 (so, for instance, 2 + 3 = 1).

Parameters
rhsthe qitmask to add to this.
Returns
a reference to this qitmask.

◆ operator-=()

template<typename T , typename U = T>
Qitmask2< T, U > & regina::Qitmask2< T, U >::operator-= ( const Qitmask2< T, U > &  rhs)
inline

Sets this to the difference of this and the given qitmask.

Each pair of qits is subtracted modulo 4 (so, for instance, 1 - 3 = 2).

Parameters
rhsthe qitmask to subtract from this.
Returns
a reference to this qitmask.

◆ operator=()

template<typename T , typename U = T>
Qitmask2< T, U > & regina::Qitmask2< T, U >::operator= ( const Qitmask2< T, U > &  other)
default

Sets this qitmask to a copy of the given qitmask.

Parameters
otherthe qitmask to clone.
Returns
a reference to this qitmask.

◆ operator==()

template<typename T , typename U = T>
bool regina::Qitmask2< T, U >::operator== ( const Qitmask2< T, U > &  other) const
inline

Determines whether this and the given qitmask are identical.

Parameters
otherthe qitmask to compare against this.
Returns
true if and only if this and the given qitmask are identical.

◆ reset()

template<typename T , typename U = T>
void regina::Qitmask2< T, U >::reset ( )
inline

Sets all qits of this qitmask to 0.

◆ set()

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

Sets the given qit of this qitmask to the given value.

Parameters
indexindicates which qit 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 qit; this must be 0, 1, 2 or 3.

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

Copyright © 1999-2021, 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@maths.uq.edu.au).