liblevenshtein 4.0.0
A library for generating Finite State Transducers based on Levenshtein Automata.
Loading...
Searching...
No Matches
distance.cpp
Go to the documentation of this file.
1#include <cstdint>
2
6
7namespace liblevenshtein {
8
9template <>
10auto distance<Algorithm::STANDARD>(State *state, std::size_t query_length)
11 -> std::size_t {
12 std::size_t min_distance = SIZE_MAX;
13 for (Position *position : *state) {
14 std::size_t i = position->term_index();
15 std::size_t e = position->num_errors();
16 std::size_t distance = query_length - i + e;
17 if (distance < min_distance) {
18 min_distance = distance;
19 }
20 }
21 return min_distance;
22}
23
24template <>
25auto distance<Algorithm::TRANSPOSITION>(State *state, std::size_t query_length)
26 -> std::size_t {
27 std::size_t min_distance = SIZE_MAX;
28 for (Position *position : *state) {
29 if (!position->is_special()) {
30 std::size_t i = position->term_index();
31 std::size_t e = position->num_errors();
32 std::size_t distance = query_length - i + e;
33 if (distance < min_distance) {
34 min_distance = distance;
35 }
36 }
37 }
38 return min_distance;
39}
40
41template <>
43 std::size_t query_length)
44 -> std::size_t {
45 std::size_t min_distance = SIZE_MAX;
46 for (Position *position : *state) {
47 if (!position->is_special()) {
48 std::size_t i = position->term_index();
49 std::size_t e = position->num_errors();
50 std::size_t distance = query_length - i + e;
51 if (distance < min_distance) {
52 min_distance = distance;
53 }
54 }
55 }
56 return min_distance;
57}
58
59} // namespace liblevenshtein
Represents a location within the Levenshtein automaton.
Definition position.h:11
Consists of a closure of Position nodes within the Levenshtein automaton.
Definition state.h:23
void query(ll::Dawg *dawg, const std::string &query_term, std::size_t max_distance)
Definition main.cpp:25
Various utilities regarding Levenshtein transducers.
Definition namespaces.dox:9
auto distance< Algorithm::STANDARD >(State *state, std::size_t query_length) -> std::size_t
Infers the Levenshtein distance from the given State and query length for the standard Levenshtein di...
Definition distance.cpp:10
auto distance< Algorithm::TRANSPOSITION >(State *state, std::size_t query_length) -> std::size_t
Infers the Levenshtein distance from the given State and query length for the standard Levenshtein di...
Definition distance.cpp:25
auto distance(State *state, std::size_t query_length) -> std::size_t
Infers the Levenshtein distance from the given State and query length.
auto distance< Algorithm::MERGE_AND_SPLIT >(State *state, std::size_t query_length) -> std::size_t
Infers the Levenshtein distance from the given State and query length for the standard Levenshtein di...
Definition distance.cpp:42