Wordsearch Solver
|
Utility functions. More...
Classes | |
class | FlatCharValueMap |
A small cache for each character of a word and an associated value, such as iterator into a trie for each character. More... | |
struct | ValueIteratorPair |
std::pair neater replacement with appropriate names More... | |
class | LruCache |
Quick and dirty attempt at implementing an LRU cache. More... | |
Functions | |
template<class K , class V > | |
std::ostream & | operator<< (std::ostream &os, const LruCache< K, V > &cache) |
template<class Rng > | |
auto | words_grouped_by_prefix_suffix (const Rng &words) |
This rather hefty function produces a range of ranges from the input of a range of strings (or a container holding a container of chars). More... | |
std::vector< std::string > | read_file_as_lines (const char *filepath) |
Read a file at path filepath and return it split by newlines into a std::vector<std::string> More... | |
std::vector< std::string > | read_file_as_lines (const std::string &filepath) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
std::string | read_file_as_string (const char *filepath) |
Read a file at path filepath into a std::string More... | |
std::string | read_file_as_string (const std::string &filepath) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
std::vector< std::string > | read_file_as_lines_keep_lowercase_ascii_only (const char *filepath) |
Just like read_file_as_lines() except only keeps lines where all characters are lowercase ascii. More... | |
std::vector< std::string > | read_file_as_lines_keep_lowercase_ascii_only (const std::string &filepath) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. | |
template<class String > | |
void | throw_if_not_lowercase_ascii (const String &word) |
template<class Range > | |
auto | make_adjacent_view (const Range &rng) |
Given a range [1, 2, 3, 4] , returns [{1, 2}, {2, 3}, {3, 4}] More... | |
template<class DataView , class RowIndexes > | |
auto | make_row_view (DataView &&data_view, const RowIndexes &row_indexes) |
Outputs a row view onto data_view for each difference between indexes in row_indexes . More... | |
Utility functions.
auto utility::make_adjacent_view | ( | const Range & | rng | ) |
Given a range [1, 2, 3, 4]
, returns [{1, 2}, {2, 3}, {3, 4}]
[in] | rng | A forward range or better |
auto utility::make_row_view | ( | DataView && | data_view, |
const RowIndexes & | row_indexes | ||
) |
Outputs a row view onto data_view
for each difference between indexes in row_indexes
.
[in] | data_view | A view onto data |
[in] | row_indexes | Indexes splitting the data view into rows |
Example: make_row_view("abcdef", {0, 2, 5, 6}) => ("ab", "cde", "f")
std::vector< std::string > utility::read_file_as_lines | ( | const char * | filepath | ) |
Read a file at path filepath
and return it split by newlines into a std::vector<std::string>
[in] | filepath |
std::vector<std::string>
Each line as a stringstd::runtime_error | If there is an error with file opening (file doesn't exist, etc) |
std::vector< std::string > utility::read_file_as_lines_keep_lowercase_ascii_only | ( | const char * | filepath | ) |
Just like read_file_as_lines() except only keeps lines where all characters are lowercase ascii.
Read a file at path filepath
and return it split by newlines into a std::vector<std::string>
[in] | filepath |
std::vector<std::string>
Each line as a stringstd::runtime_error | If there is an error with file opening (file doesn't exist, etc) |
std::string utility::read_file_as_string | ( | const char * | filepath | ) |
Read a file at path filepath
into a std::string
[in] | filepath |
std::string
The file in a stringstd::runtime_error | If there is an error with file opening (file doesn't exist, etc) |
void utility::throw_if_not_lowercase_ascii | ( | const String & | word | ) |
std::runtime_error |
auto utility::words_grouped_by_prefix_suffix | ( | const Rng & | words | ) |
This rather hefty function produces a range of ranges from the input of a range of strings (or a container holding a container of chars).
[in] | words | A lexicographically sorted container or view of strings |
std::runtime_error | If the input range is not sorted |
It is used for construction of tries. It returns a range of ranges that may be used as such: