TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Class defining the structure of trie node and containing the methods to perform operations on them. More...
Public Member Functions | |
Tnode (const Tnode &node) | |
Tnode & | operator= (const Tnode &node)=default |
Tnode (Tnode &&)=default | |
Tnode & | operator= (Tnode &&)=default |
uint8_t | numberOfChildren (Tnode *node) |
Function to count the number of children a node in the trie has. | |
void | Insert (const std::string &entry) |
Function to insert a word in the trie. | |
void | Delete (std::string entry) |
Function to verify presence and hence delete an entry from the trie. | |
void | DeleteFrom (Tnode *delete_from, std::string delete_string, int remove_index) |
Function recursively deletes the substring character by character iterating through the string to be deleted. It traverses till the end of word in a recursive fashion, from there it deletes characters one by one till it reaches back to the initial call. | |
bool | SearchPresence (const std::string &key) |
Function to check a word's presence in the trie (Basic) | |
void | SuggestAutocomplete (Tnode *new_root, const std::string &prefix) |
Recursive function to suggest all the entries of trie which have a given common prefix. | |
void | SearchSuggestions (const std::string &key) |
Lists out all the words in trie with the longest prefix of the search key that is present in the trie. For example - if trie contains "abc", "abcde", "abcdefg", "abcddef" and if the search key is "abcdezz", then the longest common prefix is "abcde" and hence search results will be "abcde", "abcdefg". | |
void | SuggestFreqAutocomplete (Tnode *new_root, const std::string &prefix, std::priority_queue< std::pair< int, std::string > > *suggestions) |
Recursive function to suggest most frequently searched entries of trie which have a given common prefix. | |
void | SearchFreqSuggestions (const std::string &key) |
Lists out the most frequent words in trie with the longest prefix of the search key that is present in the trie. For example - if trie contains "abc", "abcde", "abcdefg", "abcddef" and they have been previously searched for 3, 1, 2, 4 times respectively, if the search key is "ab", then the longest common prefix is "ab" and only the top 3 frequencies among the matches would be displayed viz. "abcddef", "abc", "abcdefg". | |
void | SelectionTop_3 (std::priority_queue< std::pair< int, std::string > > *suggestions) |
Function to display the 3 suggestions with highest frequency of search hits. | |
Private Attributes | |
std::vector< Tnode * > | english |
bool | endOfWord |
uint32_t | frequency |
Static Private Attributes | |
static constexpr uint8_t | ENGLISH_ALPHABET_SIZE = 26 |
Class defining the structure of trie node and containing the methods to perform operations on them.
Definition at line 37 of file trie_multiple_search.cpp.
|
inline |
Definition at line 50 of file trie_multiple_search.cpp.
|
inline |
Definition at line 56 of file trie_multiple_search.cpp.
|
inline |
Definition at line 93 of file trie_multiple_search.cpp.
void operations_on_datastructures::trie_operations::Tnode::Delete | ( | std::string | entry | ) |
Function to verify presence and hence delete an entry from the trie.
entry | string entry to be deleted from the trie |
Definition at line 153 of file trie_multiple_search.cpp.
void operations_on_datastructures::trie_operations::Tnode::DeleteFrom | ( | Tnode * | delete_from, |
std::string | delete_string, | ||
int | remove_index ) |
Function recursively deletes the substring character by character iterating through the string to be deleted. It traverses till the end of word in a recursive fashion, from there it deletes characters one by one till it reaches back to the initial call.
delete_from | the acting root to the required suffix to be deleted |
delete_string | the string to be deleted from the trie |
remove_index | index denoting the beginning of the substring to be deleted |
Definition at line 137 of file trie_multiple_search.cpp.
void operations_on_datastructures::trie_operations::Tnode::Insert | ( | const std::string & | entry | ) |
Function to insert a word in the trie.
entry | string entry to be inserted in the trie |
Definition at line 107 of file trie_multiple_search.cpp.
|
inline |
Function to count the number of children a node in the trie has.
node | a trie node whose children need to be counted |
Definition at line 72 of file trie_multiple_search.cpp.
void operations_on_datastructures::trie_operations::Tnode::SearchFreqSuggestions | ( | const std::string & | key | ) |
Lists out the most frequent words in trie with the longest prefix of the search key that is present in the trie. For example - if trie contains "abc", "abcde", "abcdefg", "abcddef" and they have been previously searched for 3, 1, 2, 4 times respectively, if the search key is "ab", then the longest common prefix is "ab" and only the top 3 frequencies among the matches would be displayed viz. "abcddef", "abc", "abcdefg".
key | the string key to be searched for suggestions |
Definition at line 368 of file trie_multiple_search.cpp.
bool operations_on_datastructures::trie_operations::Tnode::SearchPresence | ( | const std::string & | key | ) |
Function to check a word's presence in the trie (Basic)
key | the string key to be searched in the trie |
Definition at line 220 of file trie_multiple_search.cpp.
void operations_on_datastructures::trie_operations::Tnode::SearchSuggestions | ( | const std::string & | key | ) |
Lists out all the words in trie with the longest prefix of the search key that is present in the trie. For example - if trie contains "abc", "abcde", "abcdefg", "abcddef" and if the search key is "abcdezz", then the longest common prefix is "abcde" and hence search results will be "abcde", "abcdefg".
key | the string key to be searched for suggestions |
Definition at line 274 of file trie_multiple_search.cpp.
void operations_on_datastructures::trie_operations::Tnode::SelectionTop_3 | ( | std::priority_queue< std::pair< int, std::string > > * | suggestions | ) |
Function to display the 3 suggestions with highest frequency of search hits.
suggestions | a max heap that contains pairs of (frequency, word) heapified based on frequency |
Definition at line 320 of file trie_multiple_search.cpp.
void operations_on_datastructures::trie_operations::Tnode::SuggestAutocomplete | ( | Tnode * | new_root, |
const std::string & | prefix ) |
Recursive function to suggest all the entries of trie which have a given common prefix.
new_root | pointer pointing to the node corresponding to the last char of prefix |
prefix | the common prefix that all the suggestions must have |
Definition at line 249 of file trie_multiple_search.cpp.
void operations_on_datastructures::trie_operations::Tnode::SuggestFreqAutocomplete | ( | Tnode * | new_root, |
const std::string & | prefix, | ||
std::priority_queue< std::pair< int, std::string > > * | suggestions ) |
Recursive function to suggest most frequently searched entries of trie which have a given common prefix.
new_root | pointer pointing to the node corresponding to the last char of prefix |
prefix | the common prefix that all the suggestions must have |
suggestions | a max heap that contains pairs of (frequency, word) heapified based on frequency |
Definition at line 340 of file trie_multiple_search.cpp.
|
private |
Definition at line 44 of file trie_multiple_search.cpp.
|
private |
Definition at line 41 of file trie_multiple_search.cpp.
|
staticconstexprprivate |
Definition at line 39 of file trie_multiple_search.cpp.
|
private |
Definition at line 47 of file trie_multiple_search.cpp.