liblevenshtein 4.0.0
A library for generating Finite State Transducers based on Levenshtein Automata.
Loading...
Searching...
No Matches
dawg_node.h
Go to the documentation of this file.
1#ifndef LIBLEVENSHTEIN_COLLECTION_DAWG_NODE_H
2#define LIBLEVENSHTEIN_COLLECTION_DAWG_NODE_H
3
4#include <functional>
5#include <map>
6
7
8namespace liblevenshtein {
9
20class DawgNode {
21public:
22
29 DawgNode(bool is_final = false);
30
38 DawgNode(std::map<char, DawgNode *>& edges, bool is_final = false);
39
46 void is_final(bool is_final);
47
55 [[nodiscard]] auto is_final() const -> bool;
56
64 void for_each_edge(const std::function<void(char, DawgNode *)> &fn) const;
65
74 [[nodiscard]] auto transition(char label) const -> DawgNode *;
75
83 auto add_edge(char label, DawgNode *target) -> DawgNode *;
84
92 auto operator==(const DawgNode &other) const -> bool;
93
94private:
95
97 std::map<char, DawgNode *> _edges;
98
100 bool _is_final = false;
101};
102
103} // namespace liblevenshtein
104
105namespace std {
106
111template <>
112struct hash<liblevenshtein::DawgNode> {
113
120 auto operator()(const liblevenshtein::DawgNode &node) const -> size_t;
121};
122
123} // namespace std
124
125#endif // LIBLEVENSHTEIN_COLLECTION_DAWG_NODE_H
Represents a position within one or more terms of a DAWG dictionary.
Definition dawg_node.h:20
std::map< char, DawgNode * > _edges
Outgoing edges from this node.
Definition dawg_node.h:97
bool _is_final
Whether this node represents a word boundary.
Definition dawg_node.h:100
auto operator==(const DawgNode &other) const -> bool
Determines whether this node is equivalent to another.
Definition dawg_node.cpp:53
auto is_final() const -> bool
Declares whether this node represents a word boundary, or whether it immediately follows an edge havi...
Definition dawg_node.cpp:23
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
auto add_edge(char label, DawgNode *target) -> DawgNode *
Adds a new outgoing edge to this node.
Definition dawg_node.cpp:41
auto transition(char label) const -> DawgNode *
Returns the target node, following this one, along the edge annotated with the given label.
Definition dawg_node.cpp:33
DawgNode(bool is_final=false)
Constructs a new DAWG node with an optional parameter that determines whether it is final (i....
Definition dawg_node.cpp:15
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.