-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrie.h
More file actions
48 lines (40 loc) · 1.23 KB
/
Trie.h
File metadata and controls
48 lines (40 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef TRIE_H
#define TRIE_H
#include <iostream>
#include <vector>
#include <fstream>
#include <string>
#include <map>
using namespace std;
/* Trie storing the words in the dictionary along with the positions in the files these are present */
const int ALPHABET_SIZE = 255;
// structure of the node in the trie
struct TrieNode {
bool isEndOfWord;
//map<int, vector<int>> fileWithPosition;
map<int, int> fileWithCount;
struct TrieNode* children[ALPHABET_SIZE];
/*TrieNode() {
To be done ---------------
}*/
};
// Defining the Trie class
class Trie
{
private:
TrieNode *rootNode;
public:
Trie();
// ~Trie();
struct TrieNode* newNode();
void insertNode(string dictionaryWord);
bool searchWord(string wordToSearch);
map<int, int> findWordDetails (string wordToPrint);
void insertPosition(string fileWord, int fileIndex, int position);
void insertDictionaryWords(string pathOfDictionary, string type);
void insertCountInFiles(map<int,string> listOfFiles, string type);
void incrementCount(string fileWord, int fileIndex);
vector<string> findValidWords(string query);
void findValidWordsHelper(TrieNode* node, string currWord, vector<string>& validWords);
};
#endif