-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrienode.cpp
110 lines (83 loc) · 2.37 KB
/
trienode.cpp
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "trienode.h"
Trienode::Trienode()
{
this->isLast = 0;
for (int i = 0; i < 256; i++)
child[i] = NULL;
this->list = NULL;
}
Trienode::~Trienode()
{
if (list != NULL)
delete(list);
for (int i = 0; i < 256; i++)
if (child[i])
delete child[i];
}
void Trienode::insert(char* token, int id) {
Trienode *temp = this;
int n = strlen(token);
for (int i = 0; i < n; i++) {
int ascii = (int)token[i];
if (temp->child[ascii] == NULL) {
temp->child[ascii] = new Trienode();
}
temp = temp->child[ascii];
}
temp->isLast = 1;
if (temp->list == NULL)
temp->list = new listnode(id);
temp->list->add(id);
}
int Trienode::tfsearchword(int id, char* word, int curr) {
Trienode *temp = this;
int n = strlen(word);
for (int i = 0; i < n; i++) {
int ascii = (int)word[i];
if (temp->child[ascii] == NULL)
return 0;
temp = temp->child[ascii];
}
if (temp->isLast)
return temp->list->search(id);
else return 0;
}
int Trienode::dsearchword(char* word, int curr) {
Trienode *temp = this;
int n = strlen(word);
for (int i = 0; i < n; i++) {
int ascii = (int)word[i];
if (temp->child[ascii] == NULL)
return 0;
temp = temp->child[ascii];
}
if (temp->isLast)
return temp->list->volume();
else return 0;
}
void Trienode::dsearchall(char* buffer, int curr)
{
cout << "Not Updated all print..." << endl;
// buffer[curr] = value;
// if (list != NULL)
// cout << buffer << " " << list->volume() << endl;
// if (child != NULL)
// child->dsearchall(buffer, curr + 1);
// if (sibling != NULL)
// sibling->dsearchall(buffer, curr);
// buffer[curr] = '\0';
}
void Trienode::search(char* word, int curr, Scorelist* scorelist)
{
Trienode *temp = this;
int n = strlen(word);
for (int i = 0; i < n; i++) {
int ascii = (int)word[i];
if (temp->child[ascii] == NULL)
return;
temp = temp->child[ascii];
}
if (temp->isLast ) {
temp->list->passdocuments(scorelist);
}
}