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.
1
#include "
liblevenshtein/collection/dawg_iterator.h
"
2
3
4
namespace
liblevenshtein
{
5
6
DawgIterator::DawgIterator
(
DawgNode
* root) {
7
auto
*
prefix
=
new
Prefix
(root);
8
_prefixes
.push_back(
prefix
);
9
_pending
.push(
prefix
);
10
advance
();
11
}
12
13
DawgIterator::DawgIterator
(std::size_t term_index)
14
: _term_index(term_index)
15
{}
16
17
DawgIterator::~DawgIterator
() {
18
for
(
Prefix
*
prefix
:
_prefixes
) {
19
delete
prefix
;
20
}
21
}
22
23
auto
DawgIterator::operator++
() ->
DawgIterator
& {
24
advance();
25
_term_index += 1;
26
return
*
this
;
27
}
28
29
auto
DawgIterator::operator*
()
const
->
std
::
string
{
30
return
_next_value
;
31
}
32
33
auto
DawgIterator::operator==
(
const
DawgIterator
&
other
)
const
->
bool
{
34
return
_term_index ==
other
._term_index;
35
}
36
37
void
DawgIterator::advance
() {
38
if
(!
_pending
.empty()) {
39
DawgNode
* node;
40
std::string
value
;
41
Prefix
*
prefix
;
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
liblevenshtein::DawgIterator
Iterates over all the terms in a DAWG dictionary.
Definition
dawg_iterator.h:15
liblevenshtein::DawgIterator::operator++
auto operator++() -> DawgIterator &
Advances the iterator by one term.
Definition
dawg_iterator.cpp:23
liblevenshtein::DawgIterator::_prefixes
std::vector< Prefix * > _prefixes
Used to construct dictionary terms by collecting consecutive edge labels from the root node to their ...
Definition
dawg_iterator.h:72
liblevenshtein::DawgIterator::advance
void advance()
Advances this iterator by one term.
Definition
dawg_iterator.cpp:37
liblevenshtein::DawgIterator::~DawgIterator
~DawgIterator()
Cleans up all the prefixes allocated by this iterator.
Definition
dawg_iterator.cpp:17
liblevenshtein::DawgIterator::_pending
std::queue< Prefix * > _pending
Intermediate prefixes that have not reached all their final nodes yet.
Definition
dawg_iterator.h:75
liblevenshtein::DawgIterator::_next_value
std::string _next_value
Value of this iterator, i.e.
Definition
dawg_iterator.h:78
liblevenshtein::DawgIterator::DawgIterator
DawgIterator(DawgNode *root)
Constructs an iterator over the terms in a dictionary.
Definition
dawg_iterator.cpp:6
liblevenshtein::DawgIterator::operator*
auto operator*() const -> std::string
Returns the current dictionary term.
Definition
dawg_iterator.cpp:29
liblevenshtein::DawgIterator::operator==
auto operator==(const DawgIterator &other) const -> bool
Compares this iterator with one representing the boundary following the final term in the dictionary.
Definition
dawg_iterator.cpp:33
liblevenshtein::DawgNode
Represents a position within one or more terms of a DAWG dictionary.
Definition
dawg_node.h:20
liblevenshtein::DawgNode::is_final
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
liblevenshtein::DawgNode::for_each_edge
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
liblevenshtein::Prefix
Represents the prefix of a dictionary term.
Definition
prefix.h:16
dawg_iterator.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
std
STL namespace.
src
liblevenshtein
collection
dawg_iterator.cpp
Generated by
1.10.0