liblevenshtein 4.0.0
A library for generating Finite State Transducers based on Levenshtein Automata.
Loading...
Searching...
No Matches
dawg_iterator.cpp
Go to the documentation of this file.
2
3
4namespace liblevenshtein {
5
7 auto *prefix = new Prefix(root);
8 _prefixes.push_back(prefix);
9 _pending.push(prefix);
10 advance();
11}
12
13DawgIterator::DawgIterator(std::size_t term_index)
14 : _term_index(term_index)
15{}
16
18 for (Prefix* prefix : _prefixes) {
19 delete prefix;
20 }
21}
22
24 advance();
25 _term_index += 1;
26 return *this;
27}
28
30 return _next_value;
31}
32
33auto DawgIterator::operator==(const DawgIterator &other) const -> bool {
34 return _term_index == other._term_index;
35}
36
38 if (!_pending.empty()) {
39 DawgNode* node;
40 std::string value;
42
43 do {
44 prefix = _pending.front();
45 _pending.pop();
46
47 node = prefix->node();
48 node->for_each_edge([&] (char label, DawgNode* target) {
49 auto *child = new Prefix(target, prefix, label);
50 _prefixes.push_back(child);
51 _pending.push(child);
52 });
53 }
54 while (!node->is_final() && !_pending.empty());
55
56 if (node->is_final()) {
57 _next_value = prefix->str();
58 }
59 }
60}
61
62} // namespace liblevenshtein
Iterates over all the terms in a DAWG dictionary.
auto operator++() -> DawgIterator &
Advances the iterator by one term.
std::vector< Prefix * > _prefixes
Used to construct dictionary terms by collecting consecutive edge labels from the root node to their ...
void advance()
Advances this iterator by one term.
~DawgIterator()
Cleans up all the prefixes allocated by this iterator.
std::queue< Prefix * > _pending
Intermediate prefixes that have not reached all their final nodes yet.
std::string _next_value
Value of this iterator, i.e.
DawgIterator(DawgNode *root)
Constructs an iterator over the terms in a dictionary.
auto operator*() const -> std::string
Returns the current dictionary term.
auto operator==(const DawgIterator &other) const -> bool
Compares this iterator with one representing the boundary following the final term in the dictionary.
Represents a position within one or more terms of a DAWG dictionary.
Definition dawg_node.h:20
void is_final(bool is_final)
Specifies whether this node represents a word boundary, or immediately follows an edge having the fin...
Definition dawg_node.cpp:19
void for_each_edge(const std::function< void(char, DawgNode *)> &fn) const
Iterates over each outgoing edge of this node and invokes a callback function with each edge's charac...
Definition dawg_node.cpp:27
Represents the prefix of a dictionary term.
Definition prefix.h:16
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
STL namespace.