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;
3132using std::endl;
3233using std::out_of_range;
3334using std::ostream;
35+ // typedef tr1::unordered_map map;
3436
3537// TODO: upgrade it to process trace. Rule: char-->elem string-->elem_list
3638class SuffixTree {
3739public:
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() {}
4042int 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 {
5456int edge_len = -1 ;
5557bool flag = true ;
5658
57-
5859while (flag) {
5960if (edge == NULL ) {
6061edge = node->find_edge (*result);
@@ -96,27 +97,25 @@ class SuffixTree {
9697
9798struct 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?
101102string& test_node_str;
102103
103104Node * 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) {
107107begin = b;
108108end = e;
109109endpoint = 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) {
114114begin = b;
115115end = e;
116116}
117117
118118int length (void ) {
119-
120119if (end > test_node_str.size ())
121120return test_node_str.size () - begin;
122121else
@@ -128,7 +127,7 @@ class SuffixTree {
128127return me.begin < other.begin ;
129128}
130129
131- char operator [](int i) {
130+ char operator [](unsigned int i) {
132131i += begin;
133132if (i > end)
134133throw out_of_range (" Edge [] out of range." );
@@ -137,12 +136,12 @@ class SuffixTree {
137136}
138137
139138friend 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 ;
141140if (end >= edge.end )
142141end = edge.end ;
143142
144143char c;
145- for (int i=edge.begin ; i<=end; i++) {
144+ for (unsigned int i=edge.begin ; i<=end; i++) {
146145c = edge.test_node_str [i];
147146os << c;
148147}
@@ -167,8 +166,10 @@ class SuffixTree {
167166
168167friend 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
173174void add_edge (Edge* edge) {
174175if (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";
201201map<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 {
232232public:
233233Node* active_node;
234234char active_edge;
235235int 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
241241Node root;
@@ -253,7 +253,7 @@ class SuffixTree {
253253// how many suffixes is to be inserted?
254254int remainder;
255255// how many characters inserted?
256- int pos;
256+ unsigned int pos;
257257char get_ele (int i) { return test_str[i]; }
258258// insert a char from pos to suffix tree
259259int insert ();
0 commit comments