Cluedo Solver v1.0
Cluedo game solver making deductions.
Loading...
Searching...
No Matches
Cluedo::CardSet Class Reference

A set of cards. More...

#include <CardSet.hpp>

Classes

class  iterator
 An iterator for the CardSet class. More...
 

Public Member Functions

constexpr CardSet ()=default
 Constructs an empty set.
 
constexpr CardSet (std::initializer_list< Card > cards)
 
constexpr CardSet (std::bitset< CardUtils::CARD_COUNT > set)
 
constexpr std::size_t size () const
 
constexpr bool empty () const
 
constexpr bool contains (Card card) const
 
constexpr bool insert (Card card)
 
constexpr void erase (Card card)
 
constexpr void clear ()
 Clears the set.
 
constexpr bool operator== (CardSet const &other) const =default
 
constexpr bool operator!= (CardSet const &other) const =default
 
constexpr CardSetset_union (CardSet const &other)
 
constexpr bool is_subset (CardSet const &other) const
 
constexpr iterator begin () const
 Returns an iterator to the first card of the set.
 
constexpr iterator end () const
 Returns an iterator to the last card of the set.
 

Static Public Member Functions

static constexpr CardSet intersection (CardSet const &a, CardSet const &b)
 

Detailed Description

A set of cards.

This class is an optimization of what would have otherwise been std::unordered_set<Card>. Knowing that the number of cards in a Cluedo game is fixed and small we can use a std::bitset (which will probably fit in a single 32-bit integer) to store the cards.

Constructor & Destructor Documentation

◆ CardSet() [1/2]

Cluedo::CardSet::CardSet ( std::initializer_list< Card > cards)
inlineconstexpr

Constructs a set with the given cards.

Parameters
cardsThe list of cards that set will contain.

◆ CardSet() [2/2]

Cluedo::CardSet::CardSet ( std::bitset< CardUtils::CARD_COUNT > set)
inlineconstexpr

Constructs a set with the given bitset.

Parameters
setThe bitset that the set will contain.

Member Function Documentation

◆ contains()

bool Cluedo::CardSet::contains ( Card card) const
inlineconstexpr

Checks if the set contains the given card.

Parameters
cardThe card to check.
Returns
true if the set contains the card, false otherwise.

◆ empty()

bool Cluedo::CardSet::empty ( ) const
inlineconstexpr

Checks if the set is empty.

Returns
true if the set is empty, false otherwise.

◆ erase()

void Cluedo::CardSet::erase ( Card card)
inlineconstexpr

Removes a card from the set.

Parameters
cardThe card to remove.

◆ insert()

bool Cluedo::CardSet::insert ( Card card)
inlineconstexpr

Inserts a card into the set.

Parameters
cardThe card to insert.
Returns
true if the card was already in the set, false otherwise.

◆ intersection()

static constexpr CardSet Cluedo::CardSet::intersection ( CardSet const & a,
CardSet const & b )
inlinestaticconstexpr

Computes the intersection of two sets.

Parameters
aThe first set.
bThe second set.
Returns
The intersection of the a and b.

◆ is_subset()

bool Cluedo::CardSet::is_subset ( CardSet const & other) const
inlineconstexpr

Checks if the set is a subset of another set.

Parameters
otherThe other set.
Returns
true if the set is a subset of the other set, false otherwise.

◆ operator!=()

bool Cluedo::CardSet::operator!= ( CardSet const & other) const
constexprdefault

Compares two sets.

Parameters
otherThe other set.
Returns
true if the sets are not equal, false otherwise.

◆ operator==()

bool Cluedo::CardSet::operator== ( CardSet const & other) const
constexprdefault

Compares two sets.

Parameters
otherThe other set.
Returns
true if the sets are equal, false otherwise.

◆ set_union()

CardSet & Cluedo::CardSet::set_union ( CardSet const & other)
inlineconstexpr

Computes the union of two sets.

Note
The set that calls this method will be modified.
Parameters
otherThe other set
Returns
A reference to the set that called the method.

◆ size()

std::size_t Cluedo::CardSet::size ( ) const
inlineconstexpr

Returns the number of cards in the set.

Returns
The number of cards in the set.

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