예제 #1
0
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));
}
예제 #2
0
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;
}