-
Notifications
You must be signed in to change notification settings - Fork 2
/
_trie_node.h
80 lines (69 loc) · 1.58 KB
/
_trie_node.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
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <string>
#include <vector>
template <typename T>
class tnode {
public:
explicit tnode(T v, tnode<T>* p, int ascii, bool eow = false);
void addChild(tnode* child, int key);
std::string getKey();
tnode<T>* getChild(int key);
T& get();
void update(T val);
void markEnd(std::string);
bool isEnd();
tnode<T>* getParent();
int getParentIndex();
private:
T mapped_value;
int p_index;
bool isEndOfWord;
tnode<T>* parent;
std::vector <tnode<T>*> children;
std::string key;
};
template <typename T>
tnode<T>::tnode(T val, tnode<T>* p, int ascii, bool eow) {
this->mapped_value = val;
this-> isEndOfWord = eow;
this->p_index = ascii;
this-> key = "";
this->parent = p;
this->children = *(new std::vector <tnode<T>*>(128, nullptr));
}
template <typename T>
void tnode<T>::addChild(tnode* child, int key) {
this->children[(int)key] = child;
}
template <typename T>
std::string tnode<T>::getKey() {
return this->key;
}
template <typename T>
tnode<T>* tnode<T>::getChild(int key) {
return this->children[(int)key];
}
template <typename T>
T& tnode<T>::get() {
return this->mapped_value;
}
template <typename T>
void tnode<T>::update(T val) {
this->mapped_value = val;
}
template <typename T>
void tnode<T>::markEnd(std::string key) {
this->key = key;
this->isEndOfWord = true;
}
template <typename T>
bool tnode<T>::isEnd() {
return this->isEndOfWord;
}
template <typename T>
tnode<T>* tnode<T>::getParent() {
return this->parent;
}
template <typename T>
int tnode<T>::getParentIndex() {
return this->p_index;
}