liblevenshtein 4.0.0
A library for generating Finite State Transducers based on Levenshtein Automata.
Loading...
Searching...
No Matches
memoized_distance.cpp
Go to the documentation of this file.
1#include <mutex>
2
4
5using namespace std::literals;
6
8
9auto MemoizedDistance::get(const SymmetricPair &key, std::size_t &distance) -> bool {
10 std::shared_lock reader(mutex);
11 auto iter = memo.find(key);
12 if (iter != memo.end()) {
13 distance = iter->second;
14 return true;
15 }
16 return false;
17}
18
20 const std::size_t &distance) -> std::size_t {
21 std::unique_lock writer(mutex);
22 memo[key] = distance;
23 return distance;
24}
25
26auto MemoizedDistance::f(const std::string &u, std::size_t const t) -> std::string {
27 if (t < u.length()) {
28 return u.substr(1 + t);
29 }
30 return "";
31}
32
33} // namespace liblevenshtein::distance
auto get(const SymmetricPair &key, std::size_t &distance) -> bool
Collects the memoized distance between the pair of terms represented by the SymmetricPair if the dist...
static auto f(const std::string &u, std::size_t t) -> std::string
Returns the suffix of from position .
auto set(const SymmetricPair &key, const std::size_t &distance) -> std::size_t
Memoizes the distance between the SymmetricPair of terms for future reference.
Represents a pair of terms sorted, lexicographically, in ascending order.
void query(ll::Dawg *dawg, const std::string &query_term, std::size_t max_distance)
Definition main.cpp:25
Memoized, recursive distance metrics typically used to evaluate the correctness of Levenshtein automa...
auto distance(State *state, std::size_t query_length) -> std::size_t
Infers the Levenshtein distance from the given State and query length.