void Trie::insertWord(string word){
	incrementWordCount();
	TrieNode* node = root;
	for(unsigned int i = 0; i < word.length(); i++){
		if(node->findChild(word[i]) == NULL){
			node = node->insertChild(word[i]);
		}
		else{
			node = node->findChild(word[i]);
		}
	}
	node->setIsWord();
	node->instantiatePostingList(word); // implemented in trieNode
	node->setDocFreq();
}
Example #2
0
 TrieNode* buildTrieTree(vector<string>& words) {
     TrieNode* root = new TrieNode();
     for (string word : words) {
         int index = 0;
         TrieNode* cur = root;
         while (index < word.size() && cur->getNext(word[index]) != NULL) {
             cur = cur->getNext(word[index]);
             index++;
         }
         while (index < word.size()) {
             cur->setNext(word[index]);
             cur = cur->getNext(word[index]);
             index++;
         }
         cur->setIsWord(true);
     }
     return root;
 }