liblevenshtein 4.0.0
A library for generating Finite State Transducers based on Levenshtein Automata.
Loading...
Searching...
No Matches
state.h
Go to the documentation of this file.
1#ifndef LIBLEVENSHTEIN_TRANSDUCER_STATE_H
2#define LIBLEVENSHTEIN_TRANSDUCER_STATE_H
3
4#include <functional>
5#include <initializer_list>
6#include <vector>
7
9
10namespace liblevenshtein {
11
12using Comparator = std::function<int(Position *, Position *)>;
13
15class StateIterator;
16
23class State {
24public:
25
30 State() = default;
31
38 State(std::initializer_list<Position *> positions);
39
46 State(std::vector<Position *> &positions);
47
51 ~State();
52
60 void head(Position *head);
61
67 [[nodiscard]] auto head() const -> Position *;
68
74 void add(Position *next);
75
83 void insert_after(Position *curr, Position *next);
84
93
100
108
115
116private:
117
121 Position* _head = nullptr;
122
133
144 -> Position *;
145
153};
154
155} // namespace liblevenshtein
156
157#endif // LIBLEVENSHTEIN_TRANSDUCER_STATE_H
Represents a location within the Levenshtein automaton.
Definition position.h:11
Iterates over the Position nodes in the linked-list of a Levenshtein State.
Consists of a closure of Position nodes within the Levenshtein automaton.
Definition state.h:23
static auto find_middle(Position *lower) -> Position *
Finds the middle node between lower and the tail.
Definition state.cpp:118
Position * _head
First Position in the linked-list.
Definition state.h:121
void sort(const Comparator &compare)
Merge-sorts the linked-list of Positions.
Definition state.cpp:130
void insert_after(Position *curr, Position *next)
Inserts a new Position into the linked-list following an existing member.
Definition state.cpp:48
void add(Position *next)
Adds a new Position to the tail of the linked-list.
Definition state.cpp:35
auto begin() -> StateIterator
Returns an iterator over the Positions in this State, beginning at the head and traversing to the tai...
Definition state.cpp:134
auto end() -> StateIterator
Returns an iterator representing the end of the linked-list of Positions.
Definition state.cpp:138
auto head() const -> Position *
Returns the first Position in the linked-list of Position nodes.
Definition state.cpp:31
static auto merge(const Comparator &compare, Position *lower, Position *upper) -> Position *
Merge-sorts the nodes in the range between lower and upper.
Definition state.cpp:88
void remove(Position *prev, Position *curr)
Removes a Position from the linked-list.
Definition state.cpp:58
auto merge_sort(const Comparator &compare, Position *lower) -> Position *
Sorts the linked-list of Positions within the Levenshtein automaton.
Definition state.cpp:73
~State()
Frees any owned allocations.
Definition state.cpp:22
State()=default
Constructs an empty state, which is most commonly used to represent the intersection of the root node...
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
std::function< int(Position *, Position *)> Comparator
Definition state.h:12
auto compare(Position *lhs, Position *rhs) -> int
Compares two Positions within the Levenshtein transducer.