HooverChessUtils_PgnReader 0.9.0
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
hoover_chess_utils::pgn_reader::SquareSet Class Reference

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 SquareSetoperator= (const SquareSet &)=default
 Default copy assignment.
 
constexpr SquareSetoperator= (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 SquareSetoperator&= (SquareSet other) noexcept
 Assignment operator (union). Shorthand for x = x & other.
 
constexpr SquareSetoperator|= (SquareSet other) noexcept
 Assignment operator (union). Shorthand for x = x | other.
 
constexpr SquareSetoperator^= (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.
 

Detailed Description

Set of squares. Implemented using a bit-mask.

Constructor & Destructor Documentation

◆ SquareSet() [1/5]

constexpr hoover_chess_utils::pgn_reader::SquareSet::SquareSet ( )
inlineconstexprdefault

Default constructor (empty set)

◆ SquareSet() [2/5]

constexpr hoover_chess_utils::pgn_reader::SquareSet::SquareSet ( std::same_as< Square > auto...  squares)
inlineconstexprnoexcept

Constructor from a list of Squares.

Parameters
[in]squaresA list of squares to initially populate the square set

◆ ~SquareSet()

constexpr hoover_chess_utils::pgn_reader::SquareSet::~SquareSet ( )
constexprdefault

Default destructor.

◆ SquareSet() [3/5]

constexpr hoover_chess_utils::pgn_reader::SquareSet::SquareSet ( const SquareSet )
inlineconstexprdefault

Default copy constructor.

◆ SquareSet() [4/5]

constexpr hoover_chess_utils::pgn_reader::SquareSet::SquareSet ( SquareSet &&  )
inlineconstexprdefault

Default move constructor.

◆ SquareSet() [5/5]

constexpr hoover_chess_utils::pgn_reader::SquareSet::SquareSet ( std::uint64_t  mask)
inlineexplicitconstexprnoexcept

Cast operator.

Member Function Documentation

◆ all()

static constexpr SquareSet hoover_chess_utils::pgn_reader::SquareSet::all ( )
inlinestaticconstexprnoexcept

Returns a set of all squares.

Returns
Set of all squares

◆ allIfAny()

constexpr SquareSet hoover_chess_utils::pgn_reader::SquareSet::allIfAny ( ) const
inlineconstexprnoexcept

Conditional.

◆ allIfNone()

constexpr SquareSet hoover_chess_utils::pgn_reader::SquareSet::allIfNone ( ) const
inlineconstexprnoexcept

Conditional.

◆ column()

static constexpr SquareSet hoover_chess_utils::pgn_reader::SquareSet::column ( RowColumn  col)
inlinestaticconstexprnoexcept

Returns a set of squares in column number col.

Parameters
[in]colColumn number
Returns
Set of squares in column col. Range: [0, 7]
Remarks
The A-file is column 0, the B file is column 1, and so on.

◆ firstSquare()

constexpr Square hoover_chess_utils::pgn_reader::SquareSet::firstSquare ( ) const
inlineconstexprnoexcept

Returns the first (lowest-value) square in the set or Square::NONE if the set is empty.

Returns
First (lowest-value) square in the set or Square::NONE for empty set.

◆ flipVert()

constexpr SquareSet hoover_chess_utils::pgn_reader::SquareSet::flipVert ( ) const
inlineconstexprnoexcept

Flips the squares vertically (upside down)

Returns
Result

◆ isMember()

constexpr bool hoover_chess_utils::pgn_reader::SquareSet::isMember ( Square  sq) const
inlineconstexprnoexcept

Checks whether a valid square is in the set.

◆ lastSquare()

constexpr Square hoover_chess_utils::pgn_reader::SquareSet::lastSquare ( ) const
inlineconstexprnoexcept

Returns the last (highest-value) square in the set or Square::NONE if the set is empty.

Returns
First (lowest-value) square in the set or Square::NONE for empty set.

◆ none()

static constexpr SquareSet hoover_chess_utils::pgn_reader::SquareSet::none ( )
inlinestaticconstexprnoexcept

Returns an empty set.

Returns
Empty set

◆ operator std::uint64_t()

constexpr hoover_chess_utils::pgn_reader::SquareSet::operator std::uint64_t ( ) const
inlineexplicitconstexprnoexcept

Cast operator.

◆ operator!=()

constexpr bool hoover_chess_utils::pgn_reader::SquareSet::operator!= ( SquareSet  other) const
inlineconstexprnoexcept

Comparison operator (non-equality). Returns true if *this does not equal to other.

Parameters
[in]otherAnother square set
Returns
Comparison result

◆ operator&()

constexpr SquareSet hoover_chess_utils::pgn_reader::SquareSet::operator& ( SquareSet  other) const
inlineconstexprnoexcept

Returns an intersection with another square set.

Parameters
[in]otherAnother square set
Returns
Intersection of *this and other

Example

// a == SquareSet::square(Square::B3); -- column B, rank 3
Set of squares. Implemented using a bit-mask.
Definition chessboard-types-squareset.h:35
static constexpr SquareSet column(RowColumn col) noexcept
Returns a set of squares in column number col.
Definition chessboard-types-squareset.h:471
static constexpr SquareSet row(RowColumn row) noexcept
Returns a set of squares in row number row.
Definition chessboard-types-squareset.h:485

◆ operator&=()

constexpr SquareSet & hoover_chess_utils::pgn_reader::SquareSet::operator&= ( SquareSet  other)
inlineconstexprnoexcept

Assignment operator (union). Shorthand for x = x & other.

Parameters
[in]otherAnother square set
Returns
*this after assignment

◆ operator<<()

constexpr SquareSet hoover_chess_utils::pgn_reader::SquareSet::operator<< ( std::uint_fast8_t  shift) const
inlineconstexprnoexcept

Shifts left element-wise.

Parameters
[in]shiftShift amount. Range: [0, 63]
Returns
Shifted elements

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

// a == SquareSet::column(6), i.e., the G file
// b includes squares A2..A8, since A1 became A2, A2 become A3, and so
// on. A8 would have overflown to A9.

◆ operator<<=()

constexpr SquareSet hoover_chess_utils::pgn_reader::SquareSet::operator<<= ( std::uint_fast8_t  shift)
inlineconstexprnoexcept

Assignment operator (left shift). Shorthand for x = x << shift.

Parameters
[in]shiftShift amount. Range: [0, 63]
Returns
*this after assignment

◆ operator=() [1/2]

constexpr SquareSet & hoover_chess_utils::pgn_reader::SquareSet::operator= ( const SquareSet )
inlineconstexprdefault

Default copy assignment.

◆ operator=() [2/2]

constexpr SquareSet & hoover_chess_utils::pgn_reader::SquareSet::operator= ( SquareSet &&  )
inlineconstexprdefault

Default move assignment.

◆ operator==()

constexpr bool hoover_chess_utils::pgn_reader::SquareSet::operator== ( SquareSet  other) const
inlineconstexprnoexcept

Comparison operator (equality). Returns true if *this equals to other.

Parameters
[in]otherAnother square set
Returns
Comparison result

◆ operator>>()

constexpr SquareSet hoover_chess_utils::pgn_reader::SquareSet::operator>> ( std::uint_fast8_t  shift) const
inlineconstexprnoexcept

Shifts right element-wise.

Parameters
[in]shiftShift amount. Range: [0, 63]
Returns
Shifted elements

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

// a == SquareSet::column(2), i.e., the C file
// b includes squares A1..A7, since A2 became A1, A3 become A2, and so
// on. A1 would have overflown to A0.

◆ operator>>=()

constexpr SquareSet hoover_chess_utils::pgn_reader::SquareSet::operator>>= ( std::uint_fast8_t  shift)
inlineconstexprnoexcept

Assignment operator (right shift). Shorthand for x = x >> shift.

Parameters
[in]shiftShift amount. Range: [0, 63]
Returns
*this after assignment

◆ operator^()

constexpr SquareSet hoover_chess_utils::pgn_reader::SquareSet::operator^ ( SquareSet  other) const
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.

Parameters
[in]otherAnother square set
Returns
Exclusive or *this and other

The set-theoretical definition is as follows: R = (AB) ∖ (AB)

Example

// a includes squares B1..B8 and A3..H3 except B3, since B3 is
// included in both SquareSet::column(1) and SquareSet::row(2)

◆ operator^=()

constexpr SquareSet & hoover_chess_utils::pgn_reader::SquareSet::operator^= ( SquareSet  other)
inlineconstexprnoexcept

Assignment operator (union). Shorthand for x = x ^ other.

Parameters
[in]otherAnother square set
Returns
*this after assignment

◆ operator|()

constexpr SquareSet hoover_chess_utils::pgn_reader::SquareSet::operator| ( SquareSet  other) const
inlineconstexprnoexcept

Returns an union with another square set.

Parameters
[in]otherAnother square set
Returns
Union of *this and other

Example

// a includes squares B1..B8 and A3..H3.

◆ operator|=()

constexpr SquareSet & hoover_chess_utils::pgn_reader::SquareSet::operator|= ( SquareSet  other)
inlineconstexprnoexcept

Assignment operator (union). Shorthand for x = x | other.

Parameters
[in]otherAnother square set
Returns
*this after assignment

◆ operator~()

constexpr SquareSet hoover_chess_utils::pgn_reader::SquareSet::operator~ ( ) const
inlineconstexprnoexcept

Returns the complement of *this.

Returns
Set of squares not included in *this.

Example

// a == SquareSet::all()
constexpr ~SquareSet()=default
Default destructor.
static constexpr SquareSet none() noexcept
Returns an empty set.
Definition chessboard-types-squareset.h:452

◆ parallelDeposit()

SquareSet hoover_chess_utils::pgn_reader::SquareSet::parallelDeposit ( SquareSet  extractMask)
noexcept

Maps squares from *this using extraction mask. Squares are mapped as follows: mapped as follows:

  • lowest square in *this → lowest square in extractMask
  • second lowest square in *this → second lowest square in extractMask
  • ...
Parameters
[in]extractMaskExtract mask
Returns
Mapped (deposited) squares

Example

*this:

00000000
00000000
00000000
00000000
00000000
00000000
C6C7000000
C3B3D3E3F3G3C4C5

extractMask:

00000000
00100000
00100000
00100000
00100000
01011110
00100000
00000000

Output:

00000000
00C700000
00C600000
00C500000
00C400000
0B30D3E3F3G30
00C200000
00000000
Remarks
HAVE_X86_BMI2 indicates fast implementation.

◆ parallelExtract()

SquareSet hoover_chess_utils::pgn_reader::SquareSet::parallelExtract ( SquareSet  extractMask)
noexcept

Extracts squares from *this using extraction mask. The extracted squares are mapped as follows:

  • lowest square in the extraction mask → A1
  • second lowest square in the extraction mask → A2
  • ...
Parameters
[in]extractMaskExtraction mask
Returns
Extracted squares

Example

Inputs: (*this as named squares; extractMask shaded)

A8B8C8D8E8F8G8H8
A7B7C7D7E7F7G7H7
A6B6C6D6E6F6G6H6
A5B5C5D5E5F5G5H5
A4B4C4D4E4F4G4H4
A3B3C3D3E3F3G3H3
A2B2C2D2E2F2G2H2
A1B1C1D1E1F1G1H1

Output:

00000000
00000000
00000000
00000000
00000000
00000000
C6C7000000
C3B3D3E3F3G3C4C5
Remarks
HAVE_X86_BMI2 indicates fast implementation.

◆ popcount()

constexpr std::uint_fast8_t hoover_chess_utils::pgn_reader::SquareSet::popcount ( ) const
inlineconstexprnoexcept

Returns the number of squares in the set.

Returns
Number of squares in the set

◆ removeFirstSquare()

constexpr SquareSet hoover_chess_utils::pgn_reader::SquareSet::removeFirstSquare ( ) const
inlineconstexprnoexcept

Returns a square set with the first square (if any) removed.

Returns
The square set with the first square removed

◆ rotl()

constexpr SquareSet hoover_chess_utils::pgn_reader::SquareSet::rotl ( std::int_fast8_t  shift) const
inlineconstexprnoexcept

Rotates left element-wise (circular shift)

Parameters
[in]shiftShift amount. No range restrictions.
Returns
Shifted elements

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

// b includes squares A1..A8, since A1 became A2, A2 become A3, and so
// on. A8 wrap-arounds to A1 (equivalent to A9).
constexpr SquareSet rotl(std::int_fast8_t shift) const noexcept
Rotates left element-wise (circular shift)
Definition chessboard-types-squareset.h:287

◆ rotr()

constexpr SquareSet hoover_chess_utils::pgn_reader::SquareSet::rotr ( std::int_fast8_t  shift) const
inlineconstexprnoexcept

Rotates right element-wise (circular shift)

Parameters
[in]shiftShift amount. No range restrictions.
Returns
Shifted elements

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

// b includes squares A1..A8, since A2 became A1, A3 become A2, and so
// on. A1 wrap-arounds to A8 (equivalent to A0).
constexpr SquareSet rotr(std::int_fast8_t shift) const noexcept
Rotates right element-wise (circular shift)
Definition chessboard-types-squareset.h:308

◆ row()

static constexpr SquareSet hoover_chess_utils::pgn_reader::SquareSet::row ( RowColumn  row)
inlinestaticconstexprnoexcept

Returns a set of squares in row number row.

Parameters
[in]rowRow number
Returns
Set of squares in row row. Range: [0, 7]
Remarks
The 1st rank is row 0, the 2nd rank is row 1, and so on.

◆ square() [1/2]

static constexpr SquareSet hoover_chess_utils::pgn_reader::SquareSet::square ( RowColumn  col,
RowColumn  row 
)
inlinestaticconstexprnoexcept

Returns a set of single square specified by column and row numbers.

Parameters
[in]colColumn number of the square
[in]rowRow number of the square
Returns
The set containing square specified by col and row.

◆ square() [2/2]

static constexpr SquareSet hoover_chess_utils::pgn_reader::SquareSet::square ( Square  sq)
inlinestaticconstexprnoexcept

Returns a set of single square.

Parameters
[in]sqThe singleton square
Returns
The set containing sq

◆ squareOrNone()

static constexpr SquareSet hoover_chess_utils::pgn_reader::SquareSet::squareOrNone ( Square  sq)
inlinestaticconstexprnoexcept

Returns a set of 0 or 1 squares.

Parameters
[in]sqValid square or Square::NONE
Returns
The set containing sq, including empty set for Square::NONE

Member Data Documentation

◆ m_bitmask

std::uint64_t hoover_chess_utils::pgn_reader::SquareSet::m_bitmask { }
private

The set of squares. Bit N set in the mask represents square N included in the set. See Square for the square values.


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