-
Notifications
You must be signed in to change notification settings - Fork 2
/
TSuffixTree.h
72 lines (42 loc) · 1.34 KB
/
TSuffixTree.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
//
// Created by art on 18.02.19.
//
#ifndef LAB_5_TSUFFIXTREE_H
#define LAB_5_TSUFFIXTREE_H
#include <iostream>
#include <map>
#include <string>
#include <vector>
class TNode {
public:
std::map<char, TNode *> to;
std::string::iterator begin, end; //string in edge (text[ begin, end - 1 ])
TNode *suffLink;
TNode *parentNode; // for rule 2b(split)
TNode(std::string::iterator begin, std::string::iterator end);
~TNode() {};
};
class TSuffixTree {
public:
TSuffixTree(std::string str);
void TreePrint();
std::vector<int> Search(std::string pattern);
virtual ~TSuffixTree();
private:
std::string text;
TNode *root;
TNode *activeNode;
TNode *lastAdded;
TNode *lastLeaf;
bool completePhase;
int64_t activeLen; //last added suffix's len from begin to edge before leaf
int64_t lenOfLastAddedEdge; //len of full last added
int64_t skipByRule1;
void NodePrint(TNode *node, int dpth);
void Build(std::string::iterator &position);
void ImprovedAlgo(std::string::iterator positionBegin, std::string::iterator positionEnd);
void NaiveAlgo(std::string::iterator positionBegin, std::string::iterator positionEnd);
void RecursiveDestroy(TNode *node);
void SearchLeafs(TNode *node, std::vector<int> &answer, int patternLocations);
};
#endif //LAB_5_TSUFFIXTREE_H