Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
|
Trie class, implementation of trie using hashmap in each trie node for all the characters of char16_t(UTF-16)type with methods to insert, delete, search, start with and to recommend words based on a given prefix. More...
Classes | |
struct | Node |
struct representing a trie node. More... | |
Public Member Functions | |
Trie ()=default | |
< Constructor | |
void | insert (const std::string &word) |
insert the string into the trie | |
bool | search (const std::string &word) |
search a word/string inside the trie | |
bool | startwith (const std::string &prefix) |
search a word/string that starts with a given prefix | |
void | delete_word (std::string word) |
delete a word/string from a trie | |
std::vector< std::string > | get_all_words (std::vector< std::string > results, const std::shared_ptr< Node > &element, std::string prefix) |
helper function to predict/recommend words that starts with a given prefix from the end of prefix's node iterate through all the child nodes by recursively appending all the possible words below the trie | |
std::vector< std::string > | predict_words (const std::string &prefix) |
predict/recommend a word that starts with a given prefix | |
Private Attributes | |
std::shared_ptr< Node > | root_node |
declaring root node of trie | |
Trie class, implementation of trie using hashmap in each trie node for all the characters of char16_t(UTF-16)type with methods to insert, delete, search, start with and to recommend words based on a given prefix.
|
inline |
delete a word/string from a trie
word | string to delete from trie |
|
inline |
helper function to predict/recommend words that starts with a given prefix from the end of prefix's node iterate through all the child nodes by recursively appending all the possible words below the trie
prefix | string to recommend the words |
element | node at the end of the given prefix |
results | list to store the all possible words |
|
inline |
insert the string into the trie
word | string to insert in the trie |
|
inline |
predict/recommend a word that starts with a given prefix
prefix | string to search for |
< iteratively and recursively get the recommended words
|
inline |
search a word/string inside the trie
word | string to search for |
true
if found false
if not found
|
inline |
search a word/string that starts with a given prefix
prefix | string to search for |
true
if found false
if not found
|
private |
declaring root node of trie