|
| Bitmask1 () |
| Creates a new bitmask with all bits set to false . More...
|
|
| Bitmask1 (size_t) |
| Creates a new bitmask with all bits set to false . More...
|
|
| Bitmask1 (const Bitmask1< T > &src)=default |
| Creates a clone of the given bitmask. More...
|
|
void | reset () |
| Sets all bits of this bitmask to false . More...
|
|
void | reset (size_t) |
| Sets all bits of this bitmask to false . More...
|
|
Bitmask1< T > & | operator= (const Bitmask1< T > &other)=default |
| Sets this bitmask to a copy of the given bitmask. More...
|
|
void | truncate (size_t numBits) |
| Leaves the first numBits bits of this bitmask intact, but sets all subsequent bits to false . More...
|
|
bool | get (size_t index) const |
| Returns the value of the given bit of this bitmask. More...
|
|
void | set (size_t index, bool value) |
| Sets the given bit of this bitmask to the given value. More...
|
|
template<typename ForwardIterator > |
void | set (ForwardIterator indexBegin, ForwardIterator indexEnd, bool value) |
| Sets all bits in the given sorted list to the given value. More...
|
|
Bitmask1< T > & | operator&= (const Bitmask1< T > &other) |
| Sets this to the intersection of this and the given bitmask. More...
|
|
Bitmask1< T > & | operator|= (const Bitmask1< T > &other) |
| Sets this to the union of this and the given bitmask. More...
|
|
Bitmask1< T > & | operator^= (const Bitmask1< T > &other) |
| Sets this to the exclusive disjunction (XOR) of this and the given bitmask. More...
|
|
Bitmask1< T > & | operator-= (const Bitmask1< T > &other) |
| Sets this to the set difference of this and the given bitmask. More...
|
|
void | flip () |
| Negates every bit in this bitmask. More...
|
|
bool | operator== (const Bitmask1< T > &other) const |
| Determines whether this and the given bitmask are identical. More...
|
|
bool | operator!= (const Bitmask1< T > &other) const |
| Determines whether this and the given bitmask are different. More...
|
|
bool | lessThan (const Bitmask1< T > &other) const |
| Determines whether this bitmask appears strictly before the given bitmask when bitmasks are sorted in lexicographical order. More...
|
|
bool | operator<= (const Bitmask1< T > &other) const |
| Determines whether this bitmask is entirely contained within the given bitmask. More...
|
|
bool | inUnion (const Bitmask1< T > &x, const Bitmask1< T > &y) const |
| Determines whether this bitmask is entirely contained within the union of the two given bitmasks. More...
|
|
bool | containsIntn (const Bitmask1< T > &x, const Bitmask1< T > &y) const |
| Determines whether this bitmask contains the intersection of the two given bitmasks. More...
|
|
size_t | bits () const |
| Returns the number of bits currently set to true in this bitmask. More...
|
|
ssize_t | firstBit () const |
| Returns the index of the first true bit in this bitmask, or -1 if there are no true bits. More...
|
|
ssize_t | lastBit () const |
| Returns the index of the last true bit in this bitmask, or -1 if there are no true bits. More...
|
|
bool | atMostOneBit () const |
| Determines whether at most one bit is set to true in this bitmask. More...
|
|
template<typename T>
class regina::Bitmask1< T >
A small but extremely fast bitmask class that can store up to 8 * sizeof(T) true-or-false bits.
This bitmask packs all of the bits together into a single variable of type T. This means that operations on bitmasks are extremely fast, because all of the bits can be processed at once.
The downside of course is that the number of bits 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 bitmask class that can store twice as many bits, see Bitmask2. For a bitmask class that can store arbitrarily many bits, see Bitmask.
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
- Type T is an unsigned integral numeric type.
- Python
- Python does not support templates, and so instead Regina's python interface offers the classes Bitmask8, Bitmask16, Bitmask32, Bitmask64, Bitmask128, and (if the machine supports 128-bit integers) Bitmask256. Each of these will be an optimised bitmask class that can hold the corresponding number of bits, and is guaranteed to be an instance of either the C++ Bitmask1<T> class (where possible) or the C++ Bitmask2<T,U> template class (if necessary).
template<typename T >
template<typename ForwardIterator >
void regina::Bitmask1< T >::set |
( |
ForwardIterator |
indexBegin, |
|
|
ForwardIterator |
indexEnd, |
|
|
bool |
value |
|
) |
| |
|
inline |
Sets all bits in the given sorted list to the given value.
This is a convenience routine for setting many bits at once. The indices of the bits to set should be sorted and stored in some container, such as a std::set or a C-style array. This routine takes iterators over this container, and sets the bits at the corresponding indices to the given value.
For example, the following code would set bits 3, 5 and 6 to true:
std::vector<unsigned> indices;
indices.push(3); indices.push(5); indices.push(6);
bitmask.set(indices.begin(), indices.end(), true);
Likewise, the following code would set bits 1, 4 and 7 to false:
unsigned indices[3] = { 1, 4, 7 };
bitmask.set(indices, indices + 3, false);
All other bits of this bitmask are unaffected by this routine.
- Precondition
- ForwardIterator is a forward iterator type that iterates over integer values.
-
The list of indices described by these iterators is in sorted order. This is to allow optimisations for larger bitmask types.
-
All indices in the given list are between 0 and (8 * sizeof(T) - 1) inclusive.
- Python
- Instead of a pair of iterators, you should pass a Python list (which, as described above, must be a sorted list of indices).
- Parameters
-
indexBegin | the beginning of the iterator range containing the sorted indices of the bits to set. |
indexEnd | the end of the iterator range containing the sorted indices of the bits to set. |
value | the value that will be assigned to each of the corresponding bits. |