Trie implementation for small-case English alphabets a-z
More...
|
|
static constexpr uint8_t | NUM_CHARS = 26 |
| | Number of alphabets.
|
| |
Trie implementation for small-case English alphabets a-z
◆ char_to_int()
| uint8_t data_structures::trie::char_to_int |
( |
const char & |
ch | ) |
const |
|
inlineprivate |
Convert a character to integer for indexing.
- Parameters
-
- Returns
- unsigned integer index
39 if (ch >=
'A' && ch <=
'Z') {
41 }
else if (ch >=
'a' && ch <=
'z') {
45 std::cerr <<
"Invalid character present. Exiting...";
static constexpr uint8_t NUM_CHARS
Number of alphabets.
Definition: trie_tree.cpp:27
◆ deleteString()
| bool data_structures::trie::deleteString |
( |
const std::string & |
str, |
|
|
int |
index |
|
) |
| |
|
inline |
removes the string if it is not a prefix of any other string, if it is then just sets the ::data_structure::trie::isEndofWord to false, else removes the given string
- Note
- the function ::data_structure::trie::deleteString might be erroneous
- Todo:
- review the function ::data_structure::trie::deleteString and the commented lines
- Parameters
-
| str | string to remove |
| index | index to remove from |
- Returns
true if successful
-
false if unsuccessful
135 if (index == str.
length()) {
168 <<
"Should not reach this line\n";
std::array< std::shared_ptr< trie >, NUM_CHARS<< 1 > arr
Recursive tree nodes as an array of shared-pointers.
Definition: trie_tree.cpp:29
bool isEndofWord
identifier if a node is terminal node
Definition: trie_tree.cpp:30
uint8_t char_to_int(const char &ch) const
Convert a character to integer for indexing.
Definition: trie_tree.cpp:38
bool deleteString(const std::string &str, int index)
Definition: trie_tree.cpp:134
◆ insert()
| void data_structures::trie::insert |
( |
const std::string & |
str | ) |
|
|
inline |
insert string into the trie
- Parameters
-
| str | String to insert in the tree |
80 for (
const char& ch : str) {
98 root->isEndofWord =
true;
trie()=default
Class default constructor.
◆ search() [1/2]
search a string exists inside a given root trie
- Parameters
-
| str | string to search for |
| index | start index to search from |
- Returns
true if found
-
false if not found
58 if (index == str.
length()) {
59 if (!root->isEndofWord) {
68 return search(root->arr[j], str, index + 1);
bool search(const std::shared_ptr< trie > &root, const std::string &str, int index)
Definition: trie_tree.cpp:56
◆ search() [2/2]
| bool data_structures::trie::search |
( |
const std::string & |
str, |
|
|
int |
index |
|
) |
| |
|
inline |
search a string exists inside the trie
- Parameters
-
| str | string to search for |
| index | start index to search from |
- Returns
true if found
-
false if not found
108 if (index == str.
length()) {
The documentation for this class was generated from the following file: