-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtree.cpp
74 lines (58 loc) · 1.19 KB
/
tree.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
#include "tree.h"
#include "bst.h"
#include "tst.h"
#include "trie.h"
#include <QDebug>
FileWordPositionWrapper::FileWordPositionWrapper(FileWordNode *start, FileWordNode *end)
{
this->start = start;
this->end = end;
}
Tree::Tree()
{
}
TreeObject::TreeObject()
{
}
void TreeObject::initTree(const short tree_type)
{
switch (tree_type) {
case Tree::BST_TREE:
this->tree = new BST;
break;
case Tree::TST_TREE:
this->tree = new TST;
break;
case Tree::TRIE_TREE:
this->tree = new Trie;
break;
}
}
Tree *TreeObject::getTree()
{
return this->tree;
}
TreeObject &TreeObject::getInstance()
{
static TreeObject instance;
return instance;
}
QStringList TreeObject::listAllWords()
{
return this->tree->listAllWords();
}
QStringList TreeObject::searchWord(QString word)
{
QStringList list;
FileWordPositionWrapper res = tree->search(word);
FileWordNode *pointer = res.start;
while (pointer != NULL)
{
list.append(Crawler::getInstance().getFileName(pointer->file_id));
pointer = pointer->next_equal;
}
return list;
}
QStringList TreeObject::searchQuery(QString query)
{
}