-
Notifications
You must be signed in to change notification settings - Fork 0
/
Trie.h
68 lines (56 loc) · 1.55 KB
/
Trie.h
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: Trie.h
* Author: s134622
*
* Created on 11. februar 2017, 17:04
*/
#ifndef TRIE_H
#define TRIE_H
#include <string>
#include <memory>
#include <vector>
#include "Node.h"
#include "Letter.h"
/**
* The class represents a Trie tree and is used to hold a dictionary.
*/
class Trie {
public:
/**
* To make the search more efficient there are 3 possible solution for each combination of letters:
* WORD_FOUND is a word
* PREFIX_FOUND is the prefix of a word
* NOT_FOUND there isn't a word that start with this combination of letters
*/
enum class TrieResult {
WORD_FOUND, PREFIX_FOUND, NOT_FOUND
};
Trie();
Trie(const std::string& path);
~Trie();
/**
* Loads a dictionary inside the trie, the dictionary has to be a word per line.
*
* @param path Used to specify the path to the dictionary.
*/
void Load(const char* path);
/**
*
* @param word Used to specify the word to be added to the dictionary.
*/
void AddWord(const std::string& word);
void AddWord(const std::vector<Letter*>& word);
/**
* @param word Used to specify the word that needs to be searched.
* @return Returns the result of the word.
*/
TrieResult SearchWord(const std::vector<Letter*>& word) const;
private:
std::unique_ptr<Node> root;
};
#endif /* TRIE_H */