Skip to content

Commit 075e05b

Browse files
committed
update suffix_tree
1 parent 106757f commit 075e05b

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

include/suffix_tree.h

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
******************************************************************************/
1818

1919
#include <string>
20+
//#include <tr1/unordered_map>
2021
#include <limits>
2122
#include <map>
2223
#include <vector>
@@ -31,12 +32,13 @@ using std::cout;
3132
using std::endl;
3233
using std::out_of_range;
3334
using std::ostream;
35+
//typedef tr1::unordered_map map;
3436

3537
// TODO: upgrade it to process trace. Rule: char-->elem string-->elem_list
3638
class SuffixTree {
3739
public:
3840
// active point is initialized as (root, None, 0), remainder initialized as 1
39-
SuffixTree(string str):test_str(str), pos(0), root(test_str), active_point(&root, 0, 0), remainder(0), ls() {}
41+
SuffixTree(string str):test_str(str), root(test_str), active_point(&root, 0, 0), remainder(0), pos(0), ls() {}
4042
int construct(void);
4143

4244
// return -1 if no such sub exist, return the beginning postion of this substring in thr original string if it exist
@@ -54,7 +56,6 @@ class SuffixTree {
5456
int edge_len = -1;
5557
bool flag = true;
5658

57-
5859
while (flag) {
5960
if (edge == NULL) {
6061
edge = node->find_edge(*result);
@@ -96,27 +97,25 @@ class SuffixTree {
9697

9798
struct Edge{
9899
// the begin and end pos of this edge, note that INT_MAX stands for #(the changing end pos of this entire string)
99-
int begin, end;
100+
unsigned int begin, end;
100101
// Is there a better way to find test_str?
101102
string& test_node_str;
102103

103104
Node * endpoint;
104105

105-
Edge(int b, int e, string& str):
106-
test_node_str(str) {
106+
Edge(unsigned int b, unsigned int e, string& str): test_node_str(str) {
107107
begin = b;
108108
end = e;
109109
endpoint = NULL;
110110
//std::cout << "Edge initialized" << std::endl;
111111
}
112112

113-
void change_edge(int b, int e) {
113+
void change_edge(unsigned int b, unsigned int e) {
114114
begin = b;
115115
end = e;
116116
}
117117

118118
int length(void) {
119-
120119
if (end > test_node_str.size())
121120
return test_node_str.size() - begin;
122121
else
@@ -128,7 +127,7 @@ class SuffixTree {
128127
return me.begin < other.begin;
129128
}
130129

131-
char operator[](int i) {
130+
char operator[](unsigned int i) {
132131
i += begin;
133132
if (i > end)
134133
throw out_of_range("Edge [] out of range.");
@@ -137,12 +136,12 @@ class SuffixTree {
137136
}
138137

139138
friend ostream& operator<<(ostream& os, Edge& edge) {
140-
int end = edge.test_node_str.size()-1;
139+
unsigned int end = edge.test_node_str.size()-1;
141140
if (end >= edge.end)
142141
end = edge.end;
143142

144143
char c;
145-
for (int i=edge.begin; i<=end; i++) {
144+
for (unsigned int i=edge.begin; i<=end; i++) {
146145
c = edge.test_node_str[i];
147146
os << c;
148147
}
@@ -167,8 +166,10 @@ class SuffixTree {
167166

168167
friend class LinkState;
169168

170-
Node(string& str) :
171-
test_node_str(str), suffix_link(NULL) { edges.clear(); findedges.clear(); }
169+
Node(string& str) : test_node_str(str), suffix_link(NULL) {
170+
edges.clear();
171+
findedges.clear();
172+
}
172173

173174
void add_edge(Edge* edge) {
174175
if (edge->endpoint == NULL)
@@ -195,8 +196,7 @@ class SuffixTree {
195196
}
196197

197198
// find edge by the first char
198-
Edge* find_edge(char c)
199-
{
199+
Edge* find_edge(char c) {
200200
//cout << "finding edge";
201201
map<char, Edge*>::iterator iter = findedges.find(c);
202202
//cout << "founded?" << endl;
@@ -228,14 +228,14 @@ class SuffixTree {
228228
};
229229
//typedef struct Node Node;
230230

231-
class ActivePoint{
231+
class ActivePoint {
232232
public:
233233
Node* active_node;
234234
char active_edge;
235235
int active_length;
236236

237-
ActivePoint(Node* node, char edge, int length):
238-
active_node(node), active_edge(edge), active_length(length) { std::cout << "ActivePoint initialized" << std::endl; }
237+
ActivePoint(Node* node, char edge, int length): active_node(node),
238+
active_edge(edge), active_length(length) { std::cout << "ActivePoint initialized" << std::endl; }
239239
};
240240

241241
Node root;
@@ -253,7 +253,7 @@ class SuffixTree {
253253
// how many suffixes is to be inserted?
254254
int remainder;
255255
// how many characters inserted?
256-
int pos;
256+
unsigned int pos;
257257
char get_ele(int i) { return test_str[i]; }
258258
// insert a char from pos to suffix tree
259259
int insert();

0 commit comments

Comments
 (0)