liblevenshtein 4.0.0
A library for generating Finite State Transducers based on Levenshtein Automata.
|
Consists of a closure of Position nodes within the Levenshtein automaton. More...
#include <state.h>
Public Member Functions | |
State ()=default | |
Constructs an empty state, which is most commonly used to represent the intersection of the root nodes of the Levenshtein and dictionary automata. | |
State (std::initializer_list< Position * > positions) | |
Constructs a new State with an initial list of Positions. | |
State (std::vector< Position * > &positions) | |
Constructs a new State with an initial list of Positions. | |
~State () | |
Frees any owned allocations. | |
void | head (Position *head) |
Sets the first element in the linked-list of Position nodes. | |
auto | head () const -> Position * |
Returns the first Position in the linked-list of Position nodes. | |
void | add (Position *next) |
Adds a new Position to the tail of the linked-list. | |
void | insert_after (Position *curr, Position *next) |
Inserts a new Position into the linked-list following an existing member. | |
void | remove (Position *prev, Position *curr) |
Removes a Position from the linked-list. | |
void | sort (const Comparator &compare) |
Merge-sorts the linked-list of Positions. | |
auto | begin () -> StateIterator |
Returns an iterator over the Positions in this State, beginning at the head and traversing to the tail. | |
auto | end () -> StateIterator |
Returns an iterator representing the end of the linked-list of Positions. | |
Private Member Functions | |
auto | merge_sort (const Comparator &compare, Position *lower) -> Position * |
Sorts the linked-list of Positions within the Levenshtein automaton. | |
Static Private Member Functions | |
static auto | merge (const Comparator &compare, Position *lower, Position *upper) -> Position * |
Merge-sorts the nodes in the range between lower and upper . | |
static auto | find_middle (Position *lower) -> Position * |
Finds the middle node between lower and the tail. | |
Private Attributes | |
Position * | _head = nullptr |
First Position in the linked-list. | |
Consists of a closure of Position nodes within the Levenshtein automaton.
Each State consists of all possible locations that are reachable within the intersection of the Levenshtein and dictionary automata, guided by the query term, at the current index within the dictionary.
|
default |
Constructs an empty state, which is most commonly used to represent the intersection of the root nodes of the Levenshtein and dictionary automata.
liblevenshtein::State::State | ( | std::initializer_list< Position * > | positions | ) |
Constructs a new State with an initial list of Positions.
positions | Initial list of Positions at the current index within the dictionary automaton. |
Definition at line 6 of file state.cpp.
References insert_after(), and query().
liblevenshtein::State::State | ( | std::vector< Position * > & | positions | ) |
Constructs a new State with an initial list of Positions.
positions | Initial list of Positions at the current index within the dictionary automaton. |
Definition at line 14 of file state.cpp.
References insert_after(), and query().
liblevenshtein::State::~State | ( | ) |
Frees any owned allocations.
Definition at line 22 of file state.cpp.
References _head.
Adds a new Position to the tail of the linked-list.
next | The Position to insert at the tail of the linked-list. |
Definition at line 35 of file state.cpp.
References _head, liblevenshtein::Position::next(), and query().
Referenced by insert_after().
auto liblevenshtein::State::begin | ( | ) | -> StateIterator |
Returns an iterator over the Positions in this State, beginning at the head and traversing to the tail.
Definition at line 134 of file state.cpp.
Referenced by liblevenshtein::merge< Algorithm::MERGE_AND_SPLIT >(), liblevenshtein::merge< Algorithm::STANDARD >(), liblevenshtein::merge< Algorithm::TRANSPOSITION >(), and liblevenshtein::UnsubsumeFn::operator()().
auto liblevenshtein::State::end | ( | ) | -> StateIterator |
Returns an iterator representing the end of the linked-list of Positions.
Definition at line 138 of file state.cpp.
Referenced by liblevenshtein::merge< Algorithm::MERGE_AND_SPLIT >(), liblevenshtein::merge< Algorithm::STANDARD >(), liblevenshtein::merge< Algorithm::TRANSPOSITION >(), and liblevenshtein::UnsubsumeFn::operator()().
Finds the middle node between lower
and the tail.
lower | Lower bound for the search for the mid-point. |
lower
and the tail. Definition at line 118 of file state.cpp.
References liblevenshtein::Position::next(), and query().
Sets the first element in the linked-list of Position nodes.
The linked-list is used with a modified version of merge-sort to merge new Positions that will not be redundant.
head | First Position in the linked-list of Positions. |
Definition at line 26 of file state.cpp.
References _head, head(), and liblevenshtein::Position::next().
Referenced by liblevenshtein::LazyQuery< Result >::advance(), liblevenshtein::StateIterator::insert(), liblevenshtein::insert_after(), and liblevenshtein::StateTransition::operator()().
Inserts a new Position into the linked-list following an existing member.
curr | Existing member of the linked-list whose follow node should be set to next. |
next | New Position to insert into the linked-list following curr. |
Definition at line 48 of file state.cpp.
References add(), liblevenshtein::Position::next(), and query().
Referenced by liblevenshtein::StateIterator::insert(), liblevenshtein::insert_after(), State(), and State().
|
staticprivate |
Merge-sorts the nodes in the range between lower
and upper
.
compare | Comparator used to lexicographically sort the Position nodes. |
lower | Lower bound of sortation. |
upper | Upper bound of sortation. |
Definition at line 88 of file state.cpp.
References liblevenshtein::compare(), liblevenshtein::Position::next(), and query().
|
private |
Sorts the linked-list of Positions within the Levenshtein automaton.
compare | Algorithm-specific comparator for sorting the linked-list of Position nodes. |
lower | Lower bound of linked-list nodes for the current branch of sortation. |
Definition at line 73 of file state.cpp.
References liblevenshtein::compare(), liblevenshtein::merge(), liblevenshtein::Position::next(), and query().
Referenced by sort().
Removes a Position from the linked-list.
By convention, prev must be the immediately preceding Position in the linked-list to curr.
prev | Position in the linked-list preceding the one to remove. |
curr | Position in the linked-lsit to remove. |
Definition at line 58 of file state.cpp.
References _head, liblevenshtein::Position::next(), and query().
Referenced by liblevenshtein::StateIterator::remove().
void liblevenshtein::State::sort | ( | const Comparator & | compare | ) |
Merge-sorts the linked-list of Positions.
compare | Comparator to use during sortation. |
Definition at line 130 of file state.cpp.
References _head, liblevenshtein::compare(), and merge_sort().