Wordsearch Solver
Public Member Functions | Private Member Functions | Private Attributes | List of all members
solver::SolverDictWrapper Class Reference

A type erased wrapper around a particular solver dictionary implementation. More...

#include <solver.hpp>

Public Member Functions

template<class SolverDict , class Words >
 SolverDictWrapper (const SolverDict &solver_dict, Words &&words)
 
 SolverDictWrapper (SolverDictWrapper &&)=default
 
SolverDictWrapperoperator= (SolverDictWrapper &&)=default
 
std::size_t size () const
 The number of whole words in this dictionary.
 
bool empty () const
 Checks if this dictionary is empty.
 
bool contains (const std::string_view word) const
 Check if this dictionary contains word. More...
 
bool further (const std::string_view word) const
 Check if this dictionary might contain words with word as a prefix. More...
 
template<class OutputIndexIterator >
void contains_further (const std::string_view stem, const std::string_view suffixes, OutputIndexIterator contains_further_it) const
 For each char in suffix appended to stem, check whether this dictionary contains this word and if it may contain longer words with this prefix. More...
 

Private Member Functions

template<class Func >
auto run (Func &&func) const
 

Private Attributes

std::variant< WORDSEARCH_DICTIONARY_CLASSES > t_
 

Detailed Description

A type erased wrapper around a particular solver dictionary implementation.

Instances of this should be constructed by SolverDictFactory::make()

Note
Uses std::variant for type erasure internally, so will need to be recompiled if the list of available solver types in the macro WORDSEARCH_DICTIONARY_CLASSES changes.

Member Function Documentation

◆ contains()

bool solver::SolverDictWrapper::contains ( const std::string_view  word) const

Check if this dictionary contains word.

Parameters
[in]wordThe word to check
Returns
true if word is present, else false

◆ contains_further()

template<class OutputIndexIterator >
void solver::SolverDictWrapper::contains_further ( const std::string_view  stem,
const std::string_view  suffixes,
OutputIndexIterator  contains_further_it 
) const

For each char in suffix appended to stem, check whether this dictionary contains this word and if it may contain longer words with this prefix.

Parameters
[in]stem
[in]suffixes
[out]contains_further_itThis function is what the solver algorithm calls every iteration to ask the dictionary solver implementation to do its work.

contains_further_it should be assigned to and incremented like an output iterator. The value written should be a std::pair<bool, bool>.

Example contains_further implementation:

const auto* node = this->search(stem);
if (!node) {
return;
}
for (const auto [i, c] : ranges::views::enumerate(suffixes)) {
const std::string_view suffix = {&c, 1};
const auto contains = detail::contains(*node, suffix);
const auto further = detail::further(*node, suffix);
*contains_further_it++ = {contains, further};
}
bool further(const std::string_view word) const
Check if this dictionary might contain words with word as a prefix.
Definition: solver.cpp:48
bool contains(const std::string_view word) const
Check if this dictionary contains word.
Definition: solver.cpp:44

Each character's position in suffix corresponds to the order that that suffix's output should be written to contains_further_it.

suffixes is not guaranteed to be sorted.

◆ further()

bool solver::SolverDictWrapper::further ( const std::string_view  word) const

Check if this dictionary might contain words with word as a prefix.

Parameters
[in]wordThe prefix to check
Returns
false if there are no more strings in the dictionary with word as a prefix, true if there might be.
Note
Some solvers do not conclusively know whether, for a prefix word, there are more words that contain that prefix. This is acceptable, though sub-optimal and will result in wasted search time, as long as eventually this returns false, assuming for word there are in fact no more words with that prefix.

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