Wordsearch Solver
|
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 | |
SolverDictWrapper & | operator= (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_ |
A type erased wrapper around a particular solver dictionary implementation.
Instances of this should be constructed by SolverDictFactory::make()
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. bool solver::SolverDictWrapper::contains | ( | const std::string_view | word | ) | const |
Check if this dictionary contains word
.
[in] | word | The word to check |
true
if word
is present, else false
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.
[in] | stem | |
[in] | suffixes | |
[out] | contains_further_it | This 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:
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.
bool solver::SolverDictWrapper::further | ( | const std::string_view | word | ) | const |
Check if this dictionary might contain words with word
as a prefix.
[in] | word | The prefix to check |
false
if there are no more strings in the dictionary with word
as a prefix, true
if there might be.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.