CGAL 6.1 - Homological Discrete Vector Fields
Loading...
Searching...
No Matches

#include <CGAL/OSM/Bitboard.h>

Definition

The class Bitboard implements an accelerating structure, derived from the chess community.

This structure maps stores a sequence of bits. However, unlike vectors or arrays, it provides fast forward and reverse iterators over 1 bits. It is used in OSM::Sparse_matrix to build a fast iterator over non-zero chains.

Classes

struct  iterator
 
struct  reverse_iterator
 

Public Member Functions

 Bitboard ()
 Bitboard default constructor.
 
 Bitboard (const std::vector< std::uint64_t > &_bitboard)
 Bitboard value intializer.
 
 Bitboard (const std::size_t _size, bool empty=true)
 Bitboard size initializer.
 
 Bitboard (const Bitboard &_bitboard)
 Bitboard copy constructor.
 
Bitboardoperator= (const Bitboard &_bitboard)
 Bitboard assign operator.
 
Bitboardbit_not ()
 Bitwise NOT on a bitboard.
 
iterator begin () const
 Bitboard begin iterator that allows to loop through all non-null indices.
 
iterator end () const
 Bitboard past-the-end iterator.
 
reverse_iterator reverse_begin () const
 Bitboard reverse_begin reverse_iterator that allows to loop through all non-null indices in decreasing order.
 
reverse_iterator reverse_begin (size_t index) const
 
reverse_iterator reverse_end () const
 Bitboard past-the-end reverse_iterator.
 
Bitboardoperator|= (const Bitboard &_other)
 Bitwise OR between two bitboards.
 
Bitboardoperator|= (const std::size_t &_other)
 Bitwise OR between a bitboard and a single bit at given position.
 
Bitboardoperator&= (const Bitboard &_other)
 Bitwise AND between two bitboards.
 
Bitboardoperator&= (const std::size_t &_other)
 Bitwise AND between a bitboard and a single bit at given position.
 
Bitboardoperator^= (const Bitboard &_other)
 Bitwise XOR between two bitboards.
 
Bitboardoperator^= (const std::size_t &_other)
 Bitwise XOR between a bitboard and a single bit at given position.
 
void toggle (const std::size_t &_index)
 Toggle on and off a given bit.
 
void setOn (const std::size_t &_index)
 Toggle on a given bit.
 
void setOff (const std::size_t &_index)
 Toggle off a given bit.
 
bool isOn (const std::size_t &_index) const
 
size_t size () const
 

Static Public Member Functions

static std::size_t bitIndex (std::uint64_t _value)
 Compute fast 64bit int log2.
 

Friends

Bitboard operator~ (const Bitboard &_bitboard)
 Bitwise NOT of a bitboard.
 
std::ostream & operator<< (std::ostream &_stream, const Bitboard &_bitboard)
 Stream operator that displays all bits.
 
Bitboard operator| (const Bitboard &_left, const Bitboard &_right)
 Bitwise OR between two bitboards.
 
Bitboard operator| (const Bitboard &_left, const std::size_t &_right)
 Bitwise OR between a bitboard and a single bit at given position.
 
Bitboard operator| (const std::size_t &_left, const Bitboard &_right)
 Bitwise OR between a bitboard and a single bit at given position.
 
Bitboard operator& (const Bitboard &_left, const Bitboard &_right)
 Bitwise AND between two bitboards.
 
Bitboard operator& (const Bitboard &_left, const std::size_t &_right)
 Bitwise AND between a bitboard and a single bit at given position.
 
Bitboard operator& (const std::size_t &_left, const Bitboard &_right)
 Bitwise AND between a bitboard and a single bit at given position.
 
Bitboard operator^ (const Bitboard &_left, const Bitboard &_right)
 Bitwise XOR between two bitboards.
 
Bitboard operator^ (const Bitboard &_left, const std::size_t &_right)
 Bitwise XOR between a bitboard and a single bit at given position.
 
Bitboard operator^ (const std::size_t &_left, const Bitboard &_right)
 Bitwise XOR between a bitboard and a single bit at given position.
 

Constructor & Destructor Documentation

◆ Bitboard() [1/4]

CGAL::OSM::Bitboard::Bitboard ( )

Bitboard default constructor.

Initialize bitboard with all zeros and size 64.

◆ Bitboard() [2/4]

CGAL::OSM::Bitboard::Bitboard ( const std::vector< std::uint64_t > &  _bitboard)

Bitboard value intializer.

Initialize bitboard with given vector of bitboards.

Parameters
[in]_bitboardThe vector of 64bit ints.

◆ Bitboard() [3/4]

CGAL::OSM::Bitboard::Bitboard ( const std::size_t  _size,
bool  empty = true 
)

Bitboard size initializer.

Initialize bitboard with given size.

Parameters
[in]_sizeThe size of the bitboard.
[in]emptyIf the boolean is true, create an empty bitboard (all bits set to 0), otherwise create a full bitboard (all bits set to 1).

◆ Bitboard() [4/4]

CGAL::OSM::Bitboard::Bitboard ( const Bitboard _bitboard)

Bitboard copy constructor.

Initialize bitboard with given bitboard.

Parameters
[in]_bitboardThe bitboard to copy.

Member Function Documentation

◆ begin()

iterator CGAL::OSM::Bitboard::begin ( ) const

Bitboard begin iterator that allows to loop through all non-null indices.

Returns
The begin iterator.
Note
The iterator is constant.

◆ bit_not()

Bitboard & CGAL::OSM::Bitboard::bit_not ( )

Bitwise NOT on a bitboard.

Returns
The reference to the NOTed bitboard.

◆ bitIndex()

static std::size_t CGAL::OSM::Bitboard::bitIndex ( std::uint64_t  _value)
static

Compute fast 64bit int log2.

Precondition
The value must have a population count of 1.
Parameters
[in]_valueThe value we want to get the bit index (i.e. log2).
Returns
The bit position.

◆ end()

iterator CGAL::OSM::Bitboard::end ( ) const

Bitboard past-the-end iterator.

Returns
The past-the-end iterator.
Note
The iterator is constant.

◆ operator&=() [1/2]

Bitboard & CGAL::OSM::Bitboard::operator&= ( const Bitboard _other)

Bitwise AND between two bitboards.

Parameters
[in]_otherThe other bitboard.
Returns
The reference to the ANDed bitboard.

◆ operator&=() [2/2]

Bitboard & CGAL::OSM::Bitboard::operator&= ( const std::size_t &  _other)

Bitwise AND between a bitboard and a single bit at given position.

Parameters
[in]_otherThe bit position.
Returns
The reference to the ANDed bitboard.

◆ operator=()

Bitboard & CGAL::OSM::Bitboard::operator= ( const Bitboard _bitboard)

Bitboard assign operator.

Initialize bitboard with given bitboard.

Parameters
[in]_bitboardThe bitboard to copy.

◆ operator^=() [1/2]

Bitboard & CGAL::OSM::Bitboard::operator^= ( const Bitboard _other)

Bitwise XOR between two bitboards.

Parameters
[in]_otherThe other bitboard.
Returns
The reference to the XORed bitboard.

◆ operator^=() [2/2]

Bitboard & CGAL::OSM::Bitboard::operator^= ( const std::size_t &  _other)

Bitwise XOR between a bitboard and a single bit at given position.

Parameters
[in]_otherThe bit position.
Returns
The reference to the XORed bitboard.

◆ operator|=() [1/2]

Bitboard & CGAL::OSM::Bitboard::operator|= ( const Bitboard _other)

Bitwise OR between two bitboards.

Parameters
[in]_otherThe other bitboard.
Returns
The reference to the ORed bitboard.

◆ operator|=() [2/2]

Bitboard & CGAL::OSM::Bitboard::operator|= ( const std::size_t &  _other)

Bitwise OR between a bitboard and a single bit at given position.

Parameters
[in]_otherThe bit position.
Returns
The reference to the ORed bitboard.

◆ reverse_begin()

reverse_iterator CGAL::OSM::Bitboard::reverse_begin ( ) const

Bitboard reverse_begin reverse_iterator that allows to loop through all non-null indices in decreasing order.

Returns
The reverse_begin iterator.
Note
The reverse_iterator is constant.

◆ reverse_end()

reverse_iterator CGAL::OSM::Bitboard::reverse_end ( ) const

Bitboard past-the-end reverse_iterator.

Returns
The past-the-end reverse_iterator.
Note
The reverse_iterator is constant.

◆ setOff()

void CGAL::OSM::Bitboard::setOff ( const std::size_t &  _index)

Toggle off a given bit.

Parameters
[in]_indexThe bit position.

◆ setOn()

void CGAL::OSM::Bitboard::setOn ( const std::size_t &  _index)

Toggle on a given bit.

Parameters
[in]_indexThe bit position.

◆ toggle()

void CGAL::OSM::Bitboard::toggle ( const std::size_t &  _index)

Toggle on and off a given bit.

Parameters
[in]_indexThe bit position.

Friends And Related Function Documentation

◆ operator& [1/3]

Bitboard operator& ( const Bitboard _left,
const Bitboard _right 
)
friend

Bitwise AND between two bitboards.

Parameters
[in]_leftThe left hand side.
[in]_rightThe right hand side.
Returns
A new bitboard which is the result of the AND.

◆ operator& [2/3]

Bitboard operator& ( const Bitboard _left,
const std::size_t &  _right 
)
friend

Bitwise AND between a bitboard and a single bit at given position.

Parameters
[in]_leftThe left hand side.
[in]_rightThe right hand side.
Returns
A new bitboard which is the result of the AND.

◆ operator& [3/3]

Bitboard operator& ( const std::size_t &  _left,
const Bitboard _right 
)
friend

Bitwise AND between a bitboard and a single bit at given position.

Parameters
[in]_leftThe left hand side.
[in]_rightThe right hand side.
Returns
A new bitboard which is the result of the AND.

◆ operator<<

std::ostream & operator<< ( std::ostream &  _stream,
const Bitboard _bitboard 
)
friend

Stream operator that displays all bits.

Parameters
[in,out]_streamThe stream to edit.
[in]_bitboardThe bitboard to display.
Returns
The edited stream.

◆ operator^ [1/3]

Bitboard operator^ ( const Bitboard _left,
const Bitboard _right 
)
friend

Bitwise XOR between two bitboards.

Parameters
[in]_leftThe left hand side.
[in]_rightThe right hand side.
Returns
A new bitboard which is the result of the XOR.

◆ operator^ [2/3]

Bitboard operator^ ( const Bitboard _left,
const std::size_t &  _right 
)
friend

Bitwise XOR between a bitboard and a single bit at given position.

Parameters
[in]_leftThe left hand side.
[in]_rightThe right hand side.
Returns
A new bitboard which is the result of the XOR.

◆ operator^ [3/3]

Bitboard operator^ ( const std::size_t &  _left,
const Bitboard _right 
)
friend

Bitwise XOR between a bitboard and a single bit at given position.

Parameters
[in]_leftThe left hand side.
[in]_rightThe right hand side.
Returns
A new bitboard which is the result of the XOR.

◆ operator| [1/3]

Bitboard operator| ( const Bitboard _left,
const Bitboard _right 
)
friend

Bitwise OR between two bitboards.

Parameters
[in]_leftThe left hand side.
[in]_rightThe right hand side.
Returns
A new bitboard which is the result of the OR.

◆ operator| [2/3]

Bitboard operator| ( const Bitboard _left,
const std::size_t &  _right 
)
friend

Bitwise OR between a bitboard and a single bit at given position.

Parameters
[in]_leftThe left hand side.
[in]_rightThe right hand side.
Returns
A new bitboard which is the result of the OR.

◆ operator| [3/3]

Bitboard operator| ( const std::size_t &  _left,
const Bitboard _right 
)
friend

Bitwise OR between a bitboard and a single bit at given position.

Parameters
[in]_leftThe left hand side.
[in]_rightThe right hand side.
Returns
A new bitboard which is the result of the OR.

◆ operator~

Bitboard operator~ ( const Bitboard _bitboard)
friend

Bitwise NOT of a bitboard.

Parameters
[in]_bitboardThe argument bitboard.
Returns
A new bitboard which is the result of the NOT.