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
3
#include "
liblevenshtein/transducer/distance.h
"
4
#include "
liblevenshtein/transducer/position.h
"
5
#include "
liblevenshtein/transducer/state_iterator.h
"
6
7
namespace
liblevenshtein
{
8
9
template
<>
10
auto
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
24
template
<>
25
auto
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
41
template
<>
42
auto
distance<Algorithm::MERGE_AND_SPLIT>
(
State
*state,
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
liblevenshtein::Position
Represents a location within the Levenshtein automaton.
Definition
position.h:11
liblevenshtein::State
Consists of a closure of Position nodes within the Levenshtein automaton.
Definition
state.h:23
query
void query(ll::Dawg *dawg, const std::string &query_term, std::size_t max_distance)
Definition
main.cpp:25
liblevenshtein
Various utilities regarding Levenshtein transducers.
Definition
namespaces.dox:9
liblevenshtein::distance< Algorithm::STANDARD >
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
liblevenshtein::distance< Algorithm::TRANSPOSITION >
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
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.
liblevenshtein::distance< Algorithm::MERGE_AND_SPLIT >
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
position.h
state_iterator.h
distance.h
src
liblevenshtein
transducer
distance.cpp
Generated by
1.10.0