liblevenshtein
4.0.0
A library for generating Finite State Transducers based on Levenshtein Automata.
Loading...
Searching...
No Matches
comparator.cpp
Go to the documentation of this file.
1
#include "
liblevenshtein/transducer/comparator.h
"
2
3
4
namespace
liblevenshtein
{
5
6
// We have to be careful because term_index and num_errors are unsigned integer
7
// types, so subtracting may result in an underflow.
8
9
template
<>
10
auto
compare<Algorithm::STANDARD>
(
Position
*
lhs
,
Position
*
rhs
) ->
int
{
11
if
(
lhs
->term_index() <
rhs
->term_index()) {
12
return
-1;
13
}
14
15
if
(
lhs
->term_index() >
rhs
->term_index()) {
16
return
1;
17
}
18
19
if
(
lhs
->num_errors() <
rhs
->num_errors()) {
20
return
-1;
21
}
22
23
if
(
lhs
->num_errors() >
rhs
->num_errors()) {
24
return
1;
25
}
26
27
return
0;
28
}
29
30
template
<>
31
auto
compare<Algorithm::TRANSPOSITION>
(
Position
*
lhs
,
Position
*
rhs
) ->
int
{
32
if
(
lhs
->term_index() <
rhs
->term_index()) {
33
return
-1;
34
}
35
36
if
(
lhs
->term_index() >
rhs
->term_index()) {
37
return
1;
38
}
39
40
if
(
lhs
->num_errors() <
rhs
->num_errors()) {
41
return
-1;
42
}
43
44
if
(
lhs
->num_errors() >
rhs
->num_errors()) {
45
return
1;
46
}
47
48
return
static_cast<
int
>
(
lhs
->is_special()) -
49
static_cast<
int
>
(
rhs
->is_special());
50
}
51
52
template
<>
53
auto
compare<Algorithm::MERGE_AND_SPLIT>
(
Position
*
lhs
,
Position
*
rhs
) ->
int
{
54
if
(
lhs
->term_index() <
rhs
->term_index()) {
55
return
-1;
56
}
57
58
if
(
lhs
->term_index() >
rhs
->term_index()) {
59
return
1;
60
}
61
62
if
(
lhs
->num_errors() <
rhs
->num_errors()) {
63
return
-1;
64
}
65
66
if
(
lhs
->num_errors() >
rhs
->num_errors()) {
67
return
1;
68
}
69
70
return
static_cast<
int
>
(
lhs
->is_special()) -
71
static_cast<
int
>
(
rhs
->is_special());
72
}
73
74
}
// namespace liblevenshtein
liblevenshtein::Position
Represents a location within the Levenshtein automaton.
Definition
position.h:11
comparator.h
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::compare< Algorithm::MERGE_AND_SPLIT >
auto compare< Algorithm::MERGE_AND_SPLIT >(Position *lhs, Position *rhs) -> int
Compares two Positions for the standard Levenshtein transducer extended with merge and split.
Definition
comparator.cpp:53
liblevenshtein::compare< Algorithm::STANDARD >
auto compare< Algorithm::STANDARD >(Position *lhs, Position *rhs) -> int
Compares two Positions for the standard Levenshtein transducer.
Definition
comparator.cpp:10
liblevenshtein::compare< Algorithm::TRANSPOSITION >
auto compare< Algorithm::TRANSPOSITION >(Position *lhs, Position *rhs) -> int
Compares two Positions for the standard Levenshtein transducer extended with transposition.
Definition
comparator.cpp:31
src
liblevenshtein
transducer
comparator.cpp
Generated by
1.10.0