|
| Bitmask () |
| Creates a new invalid bitmask. More...
|
|
| Bitmask (size_t length) |
| Creates a new bitmask of the given length with all bits set to false . More...
|
|
| Bitmask (const Bitmask &src) |
| Creates a clone of the given bitmask. More...
|
|
| Bitmask (Bitmask &&src) noexcept |
| Moves the contents of the given bitmask into this new bitmask. More...
|
|
| ~Bitmask () |
| Destroys this bitmask. 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...
|
|
void | reset () |
| Sets all bits of this bitmask to false . More...
|
|
void | reset (size_t length) |
| Resizes this bitmask to the given length and sets all bits to false . More...
|
|
Bitmask & | operator= (const Bitmask &other) |
| Sets this bitmask to a copy of the given bitmask. More...
|
|
Bitmask & | operator= (Bitmask &&src) noexcept |
| Moves the contents of the given bitmask into this bitmask. More...
|
|
void | swap (Bitmask &other) noexcept |
| Swaps the contents of this and 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...
|
|
Bitmask & | operator&= (const Bitmask &other) |
| Sets this to the intersection of this and the given bitmask. More...
|
|
Bitmask & | operator|= (const Bitmask &other) |
| Sets this to the union of this and the given bitmask. More...
|
|
Bitmask & | operator^= (const Bitmask &other) |
| Sets this to the exclusive disjunction (XOR) of this and the given bitmask. More...
|
|
Bitmask & | operator-= (const Bitmask &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 Bitmask &other) const |
| Determines whether this and the given bitmask are identical. More...
|
|
bool | operator!= (const Bitmask &other) const |
| Determines whether this and the given bitmask are different. More...
|
|
bool | lessThan (const Bitmask &other) const |
| Determines whether this bitmask appears strictly before the given bitmask when bitmasks are sorted in lexicographical order. More...
|
|
bool | operator<= (const Bitmask &other) const |
| Determines whether this bitmask is entirely contained within the given bitmask. More...
|
|
bool | inUnion (const Bitmask &x, const Bitmask &y) const |
| Determines whether this bitmask is entirely contained within the union of the two given bitmasks. More...
|
|
bool | containsIntn (const Bitmask &x, const Bitmask &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...
|
|
long | firstBit () const |
| Returns the index of the first true bit in this bitmask, or -1 if there are no true bits. More...
|
|
long | 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...
|
|
A bitmask that can store arbitrarily many true-or-false bits.
This bitmask packs the bits together, so that (unlike an array of bools) many bits can be stored in a single byte. As a result, operations on this class are fast because the CPU can work on many bits simultaneously.
Nevertheless, this class still has overhead because the bits must be allocated on the heap, and because every operation requires looping through the individual bytes. For reasonably small bitmasks, see the highly optimised Bitmask1 and Bitmask2 classes instead.
Once a bitmask is created, the only way its length (the number of bits) can be changed is by calling reset(size_t).
The length of the bitmask is not actually stored in this structure. This means that, upon construction (or reset), the length will be automatically rounded up to the next "raw unit of storage".
This class implements C++ move semantics and adheres to the C++ Swappable requirement. It is designed to avoid deep copies wherever possible, even when passing or returning objects by value.
- Todo:
- Optimise: Insist that sizeof(Piece) is a power of two, and replace expensive division/mod operations with cheap bit operations.
- Warning
- Because this class may increase the length of the bitmask (rounding up to the next unit of storage), bitwise computations may not give the results that you expect. In particular, flip() may set additional
true
bits in the "dead space" between the intended length and the actual length, and this may have a flow-on effect for other operations (such as subset testing, bit counting and so on). Be careful!
Sets this bitmask to a copy of the given bitmask.
If this bitmask is invalid, this assignment operator can be used to initialise it with a length.
If this bitmask has already been initialised to a different length from that of the given bitmask, the length of this bitmask will be changed accordingly.
If the given bitmask is invalid, this bitmask will become invalid also. Invalid bitmasks must be assigned a length using reset(size_t) or this assignment operator.
- Parameters
-
other | the bitmask to clone. |
- Returns
- a reference to this bitmask.
template<typename ForwardIterator >
void regina::Bitmask::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 at least zero and strictly less than the length of this bitmask.
- 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. |