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.
2
3
4namespace 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
9template <>
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
30template <>
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
52template <>
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
Represents a location within the Levenshtein automaton.
Definition position.h:11
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 compare< Algorithm::MERGE_AND_SPLIT >(Position *lhs, Position *rhs) -> int
Compares two Positions for the standard Levenshtein transducer extended with merge and split.
auto compare< Algorithm::STANDARD >(Position *lhs, Position *rhs) -> int
Compares two Positions for the standard Levenshtein transducer.
auto compare< Algorithm::TRANSPOSITION >(Position *lhs, Position *rhs) -> int
Compares two Positions for the standard Levenshtein transducer extended with transposition.