|
HooverChessUtils_PgnReader 0.9.0
|
Set of squares. Implemented using a bit-mask. More...
#include <chessboard-types-squareset.h>
Public Member Functions | |
| constexpr | SquareSet ()=default |
| Default constructor (empty set) | |
| constexpr | SquareSet (std::same_as< Square > auto... squares) noexcept |
Constructor from a list of Squares. | |
| constexpr | ~SquareSet ()=default |
| Default destructor. | |
| constexpr | SquareSet (const SquareSet &)=default |
| Default copy constructor. | |
| constexpr | SquareSet (SquareSet &&)=default |
| Default move constructor. | |
| constexpr SquareSet & | operator= (const SquareSet &)=default |
| Default copy assignment. | |
| constexpr SquareSet & | operator= (SquareSet &&)=default |
| Default move assignment. | |
| constexpr | SquareSet (std::uint64_t mask) noexcept |
| Cast operator. | |
| constexpr | operator std::uint64_t () const noexcept |
| Cast operator. | |
| constexpr std::uint_fast8_t | popcount () const noexcept |
| Returns the number of squares in the set. | |
| constexpr Square | firstSquare () const noexcept |
Returns the first (lowest-value) square in the set or Square::NONE if the set is empty. | |
| constexpr Square | lastSquare () const noexcept |
Returns the last (highest-value) square in the set or Square::NONE if the set is empty. | |
| constexpr SquareSet | removeFirstSquare () const noexcept |
| Returns a square set with the first square (if any) removed. | |
| constexpr SquareSet | operator& (SquareSet other) const noexcept |
| Returns an intersection with another square set. | |
| constexpr SquareSet | operator| (SquareSet other) const noexcept |
| Returns an union with another square set. | |
| constexpr SquareSet | operator^ (SquareSet other) const noexcept |
Returns an exclusive or with another square set. Formally, when square s is included in exactly one of *this or other, it is included in the return set. | |
| constexpr SquareSet & | operator&= (SquareSet other) noexcept |
Assignment operator (union). Shorthand for x = x & other. | |
| constexpr SquareSet & | operator|= (SquareSet other) noexcept |
Assignment operator (union). Shorthand for x = x | other. | |
| constexpr SquareSet & | operator^= (SquareSet other) noexcept |
Assignment operator (union). Shorthand for x = x ^ other. | |
| constexpr SquareSet | operator~ () const noexcept |
Returns the complement of *this. | |
| constexpr SquareSet | operator<< (std::uint_fast8_t shift) const noexcept |
| Shifts left element-wise. | |
| constexpr SquareSet | operator>> (std::uint_fast8_t shift) const noexcept |
| Shifts right element-wise. | |
| constexpr SquareSet | rotl (std::int_fast8_t shift) const noexcept |
| Rotates left element-wise (circular shift) | |
| constexpr SquareSet | rotr (std::int_fast8_t shift) const noexcept |
| Rotates right element-wise (circular shift) | |
| constexpr SquareSet | operator<<= (std::uint_fast8_t shift) noexcept |
Assignment operator (left shift). Shorthand for x = x << shift. | |
| constexpr SquareSet | operator>>= (std::uint_fast8_t shift) noexcept |
Assignment operator (right shift). Shorthand for x = x >> shift. | |
| constexpr SquareSet | flipVert () const noexcept |
| Flips the squares vertically (upside down) | |
| constexpr bool | operator== (SquareSet other) const noexcept |
Comparison operator (equality). Returns true if *this equals to other. | |
| constexpr bool | operator!= (SquareSet other) const noexcept |
Comparison operator (non-equality). Returns true if *this does not equal to other. | |
| SquareSet | parallelExtract (SquareSet extractMask) noexcept |
Extracts squares from *this using extraction mask. The extracted squares are mapped as follows: | |
| SquareSet | parallelDeposit (SquareSet extractMask) noexcept |
Maps squares from *this using extraction mask. Squares are mapped as follows: mapped as follows: | |
| constexpr bool | isMember (Square sq) const noexcept |
| Checks whether a valid square is in the set. | |
| constexpr SquareSet | allIfNone () const noexcept |
| Conditional. | |
| constexpr SquareSet | allIfAny () const noexcept |
| Conditional. | |
Static Public Member Functions | |
| static constexpr SquareSet | none () noexcept |
| Returns an empty set. | |
| static constexpr SquareSet | all () noexcept |
| Returns a set of all squares. | |
| static constexpr SquareSet | column (RowColumn col) noexcept |
Returns a set of squares in column number col. | |
| static constexpr SquareSet | row (RowColumn row) noexcept |
Returns a set of squares in row number row. | |
| static constexpr SquareSet | square (Square sq) noexcept |
| Returns a set of single square. | |
| static constexpr SquareSet | squareOrNone (Square sq) noexcept |
| Returns a set of 0 or 1 squares. | |
| static constexpr SquareSet | square (RowColumn col, RowColumn row) noexcept |
| Returns a set of single square specified by column and row numbers. | |
Private Attributes | |
| std::uint64_t | m_bitmask { } |
The set of squares. Bit N set in the mask represents square N included in the set. See Square for the square values. | |
Set of squares. Implemented using a bit-mask.
|
inlineconstexprdefault |
Default constructor (empty set)
|
inlineconstexprnoexcept |
Constructor from a list of Squares.
| [in] | squares | A list of squares to initially populate the square set |
|
constexprdefault |
Default destructor.
|
inlineconstexprdefault |
Default copy constructor.
|
inlineconstexprdefault |
Default move constructor.
|
inlineexplicitconstexprnoexcept |
Cast operator.
|
inlinestaticconstexprnoexcept |
Returns a set of all squares.
|
inlineconstexprnoexcept |
Conditional.
|
inlineconstexprnoexcept |
Conditional.
|
inlinestaticconstexprnoexcept |
Returns a set of squares in column number col.
| [in] | col | Column number |
col. Range: [0, 7]
|
inlineconstexprnoexcept |
Returns the first (lowest-value) square in the set or Square::NONE if the set is empty.
Square::NONE for empty set.
|
inlineconstexprnoexcept |
Flips the squares vertically (upside down)
|
inlineconstexprnoexcept |
Checks whether a valid square is in the set.
|
inlineconstexprnoexcept |
Returns the last (highest-value) square in the set or Square::NONE if the set is empty.
Square::NONE for empty set.
|
inlinestaticconstexprnoexcept |
Returns an empty set.
|
inlineexplicitconstexprnoexcept |
Cast operator.
|
inlineconstexprnoexcept |
Comparison operator (non-equality). Returns true if *this does not equal to other.
| [in] | other | Another square set |
|
inlineconstexprnoexcept |
Returns an intersection with another square set.
| [in] | other | Another square set |
*this and other Example
|
inlineconstexprnoexcept |
Assignment operator (union). Shorthand for x = x & other.
| [in] | other | Another square set |
*this after assignment
|
inlineconstexprnoexcept |
Shifts left element-wise.
| [in] | shift | Shift amount. Range: [0, 63] |
Every square in the set is added by shift. In case the square value overflows, it is removed from the set.
shift amount outside range is undefined behavior.
Example
|
inlineconstexprnoexcept |
Assignment operator (left shift). Shorthand for x = x << shift.
| [in] | shift | Shift amount. Range: [0, 63] |
*this after assignment
|
inlineconstexprdefault |
Default copy assignment.
|
inlineconstexprdefault |
Default move assignment.
|
inlineconstexprnoexcept |
Comparison operator (equality). Returns true if *this equals to other.
| [in] | other | Another square set |
|
inlineconstexprnoexcept |
Shifts right element-wise.
| [in] | shift | Shift amount. Range: [0, 63] |
Every square in the set is subtracted by shift. In case the square value overflows, it is removed from the set.
shift amount outside range is undefined behavior.
Example
|
inlineconstexprnoexcept |
Assignment operator (right shift). Shorthand for x = x >> shift.
| [in] | shift | Shift amount. Range: [0, 63] |
*this after assignment
|
inlineconstexprnoexcept |
Returns an exclusive or with another square set. Formally, when square s is included in exactly one of *this or other, it is included in the return set.
| [in] | other | Another square set |
*this and other The set-theoretical definition is as follows: R = (A ∪ B) ∖ (A ∩ B)
Example
|
inlineconstexprnoexcept |
Assignment operator (union). Shorthand for x = x ^ other.
| [in] | other | Another square set |
*this after assignment
|
inlineconstexprnoexcept |
Returns an union with another square set.
| [in] | other | Another square set |
*this and other Example
|
inlineconstexprnoexcept |
Assignment operator (union). Shorthand for x = x | other.
| [in] | other | Another square set |
*this after assignment
|
inlineconstexprnoexcept |
Returns the complement of *this.
*this.Example
|
noexcept |
Maps squares from *this using extraction mask. Squares are mapped as follows: mapped as follows:
*this → lowest square in extractMask *this → second lowest square in extractMask | [in] | extractMask | Extract mask |
Example
*this:
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| C6 | C7 | 0 | 0 | 0 | 0 | 0 | 0 |
| C3 | B3 | D3 | E3 | F3 | G3 | C4 | C5 |
extractMask:
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 | 1 | 1 | 1 | 0 |
| 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
Output:
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | C7 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | C6 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | C5 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | C4 | 0 | 0 | 0 | 0 | 0 |
| 0 | B3 | 0 | D3 | E3 | F3 | G3 | 0 |
| 0 | 0 | C2 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|
noexcept |
Extracts squares from *this using extraction mask. The extracted squares are mapped as follows:
| [in] | extractMask | Extraction mask |
Example
Inputs: (*this as named squares; extractMask shaded)
| A8 | B8 | C8 | D8 | E8 | F8 | G8 | H8 |
| A7 | B7 | C7 | D7 | E7 | F7 | G7 | H7 |
| A6 | B6 | C6 | D6 | E6 | F6 | G6 | H6 |
| A5 | B5 | C5 | D5 | E5 | F5 | G5 | H5 |
| A4 | B4 | C4 | D4 | E4 | F4 | G4 | H4 |
| A3 | B3 | C3 | D3 | E3 | F3 | G3 | H3 |
| A2 | B2 | C2 | D2 | E2 | F2 | G2 | H2 |
| A1 | B1 | C1 | D1 | E1 | F1 | G1 | H1 |
Output:
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| C6 | C7 | 0 | 0 | 0 | 0 | 0 | 0 |
| C3 | B3 | D3 | E3 | F3 | G3 | C4 | C5 |
|
inlineconstexprnoexcept |
Returns the number of squares in the set.
|
inlineconstexprnoexcept |
Returns a square set with the first square (if any) removed.
|
inlineconstexprnoexcept |
Rotates left element-wise (circular shift)
| [in] | shift | Shift amount. No range restrictions. |
Every square in the set is added by shift (modulo 64). That is, in case the square value overflows, it wraps around.
All values of shift are allowed.
Example
|
inlineconstexprnoexcept |
Rotates right element-wise (circular shift)
| [in] | shift | Shift amount. No range restrictions. |
Every square in the set is subtracted by shift (modulo 64). That is, in case the square value overflows, it wraps around.
All values of shift are allowed.
Example
|
inlinestaticconstexprnoexcept |
Returns a set of squares in row number row.
| [in] | row | Row number |
row. Range: [0, 7]
|
inlinestaticconstexprnoexcept |
Returns a set of single square specified by column and row numbers.
| [in] | col | Column number of the square |
| [in] | row | Row number of the square |
col and row.
|
inlinestaticconstexprnoexcept |
Returns a set of single square.
| [in] | sq | The singleton square |
sq
|
inlinestaticconstexprnoexcept |
Returns a set of 0 or 1 squares.
| [in] | sq | Valid square or Square::NONE |
sq, including empty set for Square::NONE
|
private |
The set of squares. Bit N set in the mask represents square N included in the set. See Square for the square values.