27#include <unordered_map>
34 void insert(
const std::basic_string<T> &word) {
36 for (T character: word) {
37 if (current->m_children.find(character) == current->m_children.end()) {
38 current->m_children[character] = std::make_shared<trie_t>();
40 current = current->m_children[character].get();
42 current->m_is_end_of_word =
true;
45 bool search(
const std::basic_string<T> &word) {
47 for (T character: word) {
48 if (current->m_children.find(character) == current->m_children.end()) {
51 current = current->m_children[character].get();
53 return current->m_is_end_of_word;
58 for (T character: prefix) {
59 if (current->m_children.find(character) == current->m_children.end()) {
62 current = current->m_children[character].get();
68 std::unordered_map<T, std::shared_ptr<trie_t>> m_children;
69 bool m_is_end_of_word =
false;
bool search(const std::basic_string< T > &word)
Definition: Trie.hpp:45
bool starts_with(const std::basic_string< T > &prefix)
Definition: Trie.hpp:56
void insert(const std::basic_string< T > &word)
Definition: Trie.hpp:34