liblevenshtein 4.0.0
A library for generating Finite State Transducers based on Levenshtein Automata.
Loading...
Searching...
No Matches
dawg.h
Go to the documentation of this file.
1#ifndef LIBLEVENSHTEIN_COLLECTION_DAWG_H
2#define LIBLEVENSHTEIN_COLLECTION_DAWG_H
3
4#include <iostream>
5#include <string>
6#include <unordered_set>
7
10
11namespace liblevenshtein {
12
23class Dawg {
24public:
25
35 Dawg(DawgNode* root, std::size_t size);
36
41 Dawg();
42
46 virtual ~Dawg();
47
55 virtual auto add(const std::string &term) -> bool = 0;
56
63 virtual auto remove(const std::string &term) -> bool = 0;
64
72 [[nodiscard]] auto contains(const std::string &term) const -> bool;
73
80 [[nodiscard]] auto root() const -> DawgNode *;
81
87 [[nodiscard]] auto size() const -> size_t;
88
96
106
114
117
120 friend auto operator<<(std::ostream &out, const Dawg &dawg)
121 -> std::ostream &;
122
124
127
129 std::size_t _size;
130
136 [[nodiscard]] auto all_nodes() const -> std::unordered_set<DawgNode *>;
137};
138
139} // namespace liblevenshtein
140
141
143
150template <>
152
159 auto operator()(const liblevenshtein::Dawg &dawg) const -> size_t;
160};
161} // namespace std
162
163
164#endif // LIBLEVENSHTEIN_COLLECTION_DAWG_H
Iterates over all the terms in a DAWG dictionary.
Represents a position within one or more terms of a DAWG dictionary.
Definition dawg_node.h:20
A Directed Acyclic Word Graph (DAWG) maps sequences of characters to form words; the collection of wo...
Definition dawg.h:23
virtual auto remove(const std::string &term) -> bool=0
Removes a term from this dictionary and cleans up its path.
auto contains(const std::string &term) const -> bool
Determines whether the given term is contained within this dictionary.
Definition dawg.cpp:43
std::size_t _size
Number of terms reachable from the root node.
Definition dawg.h:129
auto root() const -> DawgNode *
Returns a pointer to the root node of this dictionary from which all its terms may be determined.
Definition dawg.cpp:51
auto all_nodes() const -> std::unordered_set< DawgNode * >
Returns a set of all nodes reachable from the root, including the root.
Definition dawg.cpp:28
DawgNode * _root
Root node of this DAWG from which all its terms may be reached.
Definition dawg.h:126
auto begin() const -> DawgIterator
Returns an iterator pointing to the first term in this dictionary, from which all terms may be iterat...
Definition dawg.cpp:59
virtual ~Dawg()
Deletes all the nodes associated with this dictionary.
Definition dawg.cpp:22
auto end() const -> DawgIterator
Returns an iterator representing the boundary following the final term in this dictionary.
Definition dawg.cpp:63
auto size() const -> size_t
Returns the number of terms in this dictionary.
Definition dawg.cpp:55
virtual auto add(const std::string &term) -> bool=0
Adds a new term to this dictionary by adding missing sequential edges leading outward from the root n...
Dawg()
Constructs an empty DAWG with a default root node (there are no outgoing edges or reachable terms fro...
Definition dawg.cpp:17
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.