コード例 #1
0
ファイル: TrieChildren.cpp プロジェクト: mwaghmar/try
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
ファイル: TrieChildren.cpp プロジェクト: mwaghmar/try
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;
}