liblevenshtein 4.0.0
A library for generating Finite State Transducers based on Levenshtein Automata.
Loading...
Searching...
No Matches
memoized_distance.h
Go to the documentation of this file.
1#ifndef LIBLEVENSHTEIN_DISTANCE_MEMOIZED_DISTANCE_H
2#define LIBLEVENSHTEIN_DISTANCE_MEMOIZED_DISTANCE_H
3
4#include <shared_mutex>
5#include <string>
6#include <unordered_map>
7
10
12
16class MemoizedDistance : public Distance {
17protected:
18
30 auto get(const SymmetricPair &key, std::size_t &distance) -> bool;
31
40 auto set(const SymmetricPair &key, const std::size_t &distance)
41 -> std::size_t;
42
52 static auto f(const std::string &u, std::size_t t) -> std::string;
53
54private:
55
57 std::unordered_map<SymmetricPair, std::size_t> memo;
58
60 mutable std::shared_mutex mutex;
61};
62
63} // namespace liblevenshtein::distance
64
65#endif // LIBLEVENSHTEIN_DISTANCE_MEMOIZED_DISTANCE_H
Metric that measures the edit distance between two terms, denoted d(v,w).
Definition distance.h:21
Memoizes the distance between pairs of terms.
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.
std::unordered_map< SymmetricPair, std::size_t > memo
Memoized distances between pairs of terms.
std::shared_mutex mutex
Coordinates memoization among threads.
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.