AALanguage
The best language for those who have nothing to do
|
String-trie class for storing reserved words. More...
#include <Trie.h>
Public Member Functions | |
Trie () | |
Default constructor. | |
Trie (const Trie &)=delete | |
There is no copy constructor for this class. | |
~Trie () | |
Destructor. | |
void | add (std::string::iterator itBeg, std::string::iterator itEnd, TrieNode *start=nullptr) |
Adding a new word to the trie. | |
TrieNode * | find (std::string::iterator itBeg, std::string::iterator itEnd, TrieNode *start=nullptr) |
Searching for a string in the trie. | |
void | clear () |
Full trie clearing. | |
int | get_size () |
Gets the number of rows added to the trie. | |
Private Attributes | |
TrieNode * | _root |
|
delete |
There is no copy constructor for this class.
Trie::~Trie | ( | ) |
void Trie::add | ( | std::string::iterator | itBeg, |
std::string::iterator | itEnd, | ||
TrieNode * | start = nullptr ) |
Adding a new word to the trie.
Recursively adds a string to the tree. Asymptotics of the operation O(|S|), where |S| is the length of the input string.
itBeg | Iterator to the beginning of the string |
itEnd | Iterator to the end of the string |
start | Pointer to the node from which to start adding the string. If equal to nullptr, the addition will start from the root node. |
Definition at line 37 of file Trie.cpp.
References _root, add(), TrieNode::get_count(), TrieNode::get_ends(), and TrieNode::get_next().
Referenced by add(), and LexicalAnalyzer::LexicalAnalyzer().
TrieNode * Trie::find | ( | std::string::iterator | itBeg, |
std::string::iterator | itEnd, | ||
TrieNode * | start = nullptr ) |
Searching for a string in the trie.
Recursively finds the given string in boron. The asymptotics of the operation is O(|SS|), where |S| is the length of the input string.
itBeg | Iterator to the beginning of the string |
itEnd | Iterator to the end of the string |
start | Pointer to the node from which to start finding the string. If equal to nullptr, the finding will start from the root node. |
Definition at line 57 of file Trie.cpp.
References _root, find(), TrieNode::get_ends(), and TrieNode::get_next().
Referenced by find(), and LexicalAnalyzer::is_service().
int Trie::get_size | ( | ) |
Gets the number of rows added to the trie.
Definition at line 75 of file Trie.cpp.
References _root, and TrieNode::get_count().
|
private |