liblevenshtein 4.0.0
A library for generating Finite State Transducers based on Levenshtein Automata.
Loading...
Searching...
No Matches
sorted_dawg.h
Go to the documentation of this file.
1#ifndef LIBLEVENSHTEIN_COLLECTION_SORTED_DAWG_H
2#define LIBLEVENSHTEIN_COLLECTION_SORTED_DAWG_H
3
4#include <stack>
5#include <unordered_map>
6#include <unordered_set>
7
11
12namespace liblevenshtein {
13
20class SortedDawg : public Dawg {
21public:
22 using Dawg::Dawg;
23
28 ~SortedDawg() override;
29
37 auto add(const std::string &term) -> bool override;
38
46 auto remove(const std::string &term) -> bool override;
47
52 void init();
53
57 void clean_up();
58
63 void finish();
64
73 void minimize(std::size_t lower_bound);
74
84 auto minimized_node(DawgNode *key) const -> DawgNode *;
85
86private:
87
89 std::stack<Transition> *unchecked_transitions = nullptr;
90
92 std::unordered_map<DawgNode, DawgNode *> *minimized_nodes = nullptr;
93
95 std::unordered_set<DawgNode *> *floating_nodes = nullptr;
96
98 std::string _prev_term;
99};
100
109template <class IterType>
111
112} // namespace liblevenshtein
113
114#endif // LIBLEVENSHTEIN_COLLECTION_SORTED_DAWG_H
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
Dawg()
Constructs an empty DAWG with a default root node (there are no outgoing edges or reachable terms fro...
Definition dawg.cpp:17
A specific type of Dawg that is constructed over lexicographically sorted terms.
Definition sorted_dawg.h:20
std::unordered_set< DawgNode * > * floating_nodes
Nodes that have not been added to this Dawg.
Definition sorted_dawg.h:95
~SortedDawg() override
Cleans up any residual intermediate members used to construct the Dawg.
auto add(const std::string &term) -> bool override
Adds a new term to this dictionary.
auto minimized_node(DawgNode *key) const -> DawgNode *
Returns a DawgNode whose following suffix is equivalent to the following suffix of the given DawgNode...
std::unordered_map< DawgNode, DawgNode * > * minimized_nodes
Mapping of suffixes to DawgNodes that have been minimized.
Definition sorted_dawg.h:92
auto remove(const std::string &term) -> bool override
Removes a term from this dictionary.
std::string _prev_term
Previous term inserted into this Dawg.
Definition sorted_dawg.h:98
void minimize(std::size_t lower_bound)
Minimizes the suffixes of the unchecked paths until there are no more than lower_bound unchecked tran...
void init()
Prepares this dictionary for initialization.
void finish()
Specifies the dictionary has been fully initialized.
void clean_up()
Cleans up any intermediate members used to initialize this Dawg.
std::stack< Transition > * unchecked_transitions
Transitions whose redundancies have not been checked.
Definition sorted_dawg.h:89
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
auto sorted_dawg(IterType iter, IterType end) -> SortedDawg *
Factory function that initializes a new SortedDawg using the terms yielded from an iterator.