TrieChildren::TrieChildren(const char label, ITrie* child, const std::string& word, const bool storeEmpty) : isEmpty_(storeEmpty) { memset(children_, 0, sizeof(children_)); children_[tolower(label) - 'a'] = child; Trie t; children_[tolower(word[0]) - 'a'] = t.Add(word.substr(1)); }
ITrie* TrieChildren::Add(const std::string& word) { if( "" == word ) { isEmpty_ = true; return this; } const unsigned childIndex = tolower(word[0]) - 'a'; if( children_[childIndex] ) { children_[childIndex] = children_[childIndex]->Add(word.substr(1)); } else { Trie t; children_[childIndex] = t.Add(word.substr(1)); } return this; }