-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTSuffixTree.h
74 lines (51 loc) · 1.27 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
73
74
#ifndef TSUFTREE_H
#define TSUFTREE_H
#include <iostream>
#include <vector>
#include <map>
#include <memory>
#include <string>
#include <algorithm>
class TSuffixArray;
class TNode
{
public:
TNode (std::string::iterator start, std::string::iterator end);
~TNode() {};
std::map<char, TNode *> vertex_list;
std::string::iterator start, end;
TNode *suffixLink;
};
class TSuffixTree
{
public:
TSuffixTree(std::string str);
~TSuffixTree();
friend TSuffixArray;
private:
std::string text;
TNode *root;
TNode *takeSuffLink;
TNode *actNode;
int remainder;
int actLength;
std::string::iterator actEdge;
void Destroy (TNode *node);
void SuffixLinkAdd (TNode *node);
void DeepFirstSearch (TNode *node, std::vector<int> &result, int deep);
void Construct (std::string::iterator begin);
bool Downhill (std::string::iterator position, TNode *node);
};
class TSuffixArray
{
public:
TSuffixArray (TSuffixTree *tree);
~TSuffixArray ( ) {};
std::vector<int> Find (std::string &pattern);
private:
int FindLeft (const std::string &pattern);
int FindRight(const std::string &pattern);
std::string text;
std::vector<int> array;
};
#endif