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
3
#include "
liblevenshtein/distance/memoized_distance.h
"
4
5
using namespace
std::literals;
6
7
namespace
liblevenshtein::distance
{
8
9
auto
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
19
auto
MemoizedDistance::set
(
const
SymmetricPair
&
key
,
20
const
std::size_t &distance) -> std::size_t {
21
std::unique_lock
writer
(mutex);
22
memo[
key
] =
distance
;
23
return
distance
;
24
}
25
26
auto
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
liblevenshtein::distance::MemoizedDistance::get
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...
Definition
memoized_distance.cpp:9
liblevenshtein::distance::MemoizedDistance::f
static auto f(const std::string &u, std::size_t t) -> std::string
Returns the suffix of from position .
Definition
memoized_distance.cpp:26
liblevenshtein::distance::MemoizedDistance::set
auto set(const SymmetricPair &key, const std::size_t &distance) -> std::size_t
Memoizes the distance between the SymmetricPair of terms for future reference.
Definition
memoized_distance.cpp:19
liblevenshtein::distance::SymmetricPair
Represents a pair of terms sorted, lexicographically, in ascending order.
Definition
symmetric_pair.h:12
query
void query(ll::Dawg *dawg, const std::string &query_term, std::size_t max_distance)
Definition
main.cpp:25
memoized_distance.h
liblevenshtein::distance
Memoized, recursive distance metrics typically used to evaluate the correctness of Levenshtein automa...
Definition
namespaces.dox:16
liblevenshtein::distance
auto distance(State *state, std::size_t query_length) -> std::size_t
Infers the Levenshtein distance from the given State and query length.
src
liblevenshtein
distance
memoized_distance.cpp
Generated by
1.10.0