-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSTnode.h
executable file
·308 lines (279 loc) · 8.02 KB
/
STnode.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
/* Copyright (C) 2019 Thanasis Vergoulis
*
* This file is part of GeSuTr.
*
* GeSuTr is a free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GeSuTr is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* Contact email: [email protected]
*/
#ifndef STNODE_H
#define STNODE_H
#include <iostream>
#include <vector>
using namespace std;
/**
* Class representing a string occurrence in a leaf's list. It contains a pointer to the next item to
* implement the leaf's list of occurrences.
*
* @var _str_id The id of the string on which the occurrence is located.
* @var _occ_pos The position on the string that the occurrence appears.
* @var _next_pos Pointer to the next occurrence.
*
* @author Thanasis Vergoulis
*/
class OccPos
{
public:
long _str_id;
long _occ_pos;
OccPos* _next_pos;
/**
* The constructor of the class.
*
* @param str_id The id of the string on which the occurrence exists.
* @param occ_pos The exact position of the occurrence on the string.
* @param next_pos Pointer to the next occurrence of the same string/suffix.
*
* @author Thanasis Vergoulis
*/
OccPos(long str_id, long occ_pos, OccPos* next_pos);
};
/**
* Class representing a (generalised) suffix tree node (internal or leaf).
*
* @var _str_id The id of the string used for the label of the incoming edge.
* @var _parent A pointer to the parent of the node.
* @var _children A linked list of the children of the node. In fact its is a link to the first (leftmost) child.
* @var _right_sibling A pointer to the right sibling of the node.
* @var _in_label_start Start index of the label of the incoming edge.
* @var _in_label_end End index of the label of the incoming edge.
* @var _occ_positions If leaf this is pointer to all starting positions when the corresponding string/suffix occurs. If not leaf, it is null.
* @var _occs_num The number of occurrences in the subtree below the node.
*
* @author Thanasis Vergoulis
*/
class STnode
{
public:
/**
* The constructor of the class.
*
* @param parent Pointer to the parent node.
* @param str_id The id of the string (in the string registry-vector) used for the label of the incoming edge.
* @param start The start index of the label of the incoming edge.
* @param end The end index of the label of the incoming edge.
*
* @author Thanasis Vergoulis
*/
STnode(STnode* parent, long str_id, long start, long end);
/**
* The destructor of the class.
*
* @author Thanasis Vergoulis
*/
~STnode();
/**
* It adds a new child to the node.
*
* @param ch The pointer to the new child.
*
* @author Thanasis Vergoulis
*/
void addChild(STnode* ch);
/**
* It returns true if the node is a leaf, false otherwise.
*
* @return True if the node is leaf, false otherwise.
*
* @author Thanasis Vergoulis
*/
bool isLeaf();
/**
* It returns a pointer to the node's parent.
*
* @return A pointer to the node's parent.
*
* @author Thanasis Vergoulis
*/
STnode* getParent();
/**
* It sets the pointer to the node's parent.
*
* @param The pointer to the ndoe's parent (to be).
*
* @author Thanasis Vergoulis
*/
void setParent(STnode* parent);
/**
* It returns a pointer to the first (leftmost) child of the node. Since each child has a pointer
* to the next one, in fact this function can be used to get the linked list of a node's children.
*
* @return A pointer to the node's leftmost child.
*
* @author Thanasis Vergoulis
*/
STnode* getChildren();
/**
* It sets the pointer to the node's leftmost child.
*
* @param ch The pointer to the node's leftmost child (to be).
*
* @author Thanasis Vergoulis
*/
void setChildren(STnode* ch);
/**
* It returns a pointer to the node's right sibling.
*
* @return A pointer to the node's right sibling.
*
* @author Thanasis Vergoulis
*/
STnode* getRightSibling();
/**
* It sets the pointer to the node's right sibling.
*
* @param The pointer to the node's right siblimng (to be).
*
* @author Thanasis Vergoulis
*/
void setRightSibling(STnode* right_sib);
/**
* It returns the starting position of the label of the incoming edge.
*
* @return The starting position of the label of the incoming edge.
*
* @author Thanasis Vergoulis
*/
long getInLabelStart();
/**
* It sets the starting positions of the label of the incoming edge.
*
* @param The starting position of the label of the incoming edge (to be).
*
* @author Thanasis Vergoulis
*/
void setInLabelStart(long start);
/**
* It returns the ending position of the label of the incoming edge.
*
* @return The ending position of the label of the incoming edge.
*
* @author Thanasis Vergoulis
*/
long getInLabelEnd();
/**
* It returns the ending position of the label of the incoming edge.
*
* @return The ending position of the label of the incoming edge.
*
* @author Thanasis Vergoulis
*/
void setInLabelEnd(long end);
/**
* It returns the id of the string (in the registry-vector) used for the label of the incoming edge.
*
* @return The id of the string used for the label of the incoming edge.
*
* @author Thanasis Vergoulis
*/
long getRefStrId();
/**
* It returns the length of the label of the incoming edge.
*
* @return The length of the label of the incoming edge.
*
* @author Thanasis Vergoulis
*/
long getInLabelLength();
/**
* Adds an extra string occurrence to the list of occurrences in the leaf.
*
* @param str_id The id of the string (in the registry) on which the occurrence resides.
* @param p The position of the occurrence to be added.
*
* @author Thanasis Vergoulis
*/
void addOccPos(long str_id, long p);
/**
* Re-sets the list of string occurrences by re-setting the first occurrence (recall that the
* occurrences are a linked list).
*
* @param p Pointer to the new position of occurrence.
*
* @author Thanasis Vergoulis
*/
void setOccPos(OccPos* p);
/**
* Get a pointer to the first of the occurrences (and, thus, a way to access the whole occurrences list).
*
* @return The pointer to the first of the leafs occurrences. If not leaf then NULL.
*
* @author Thanasis Vergoulis
*/
OccPos* getOccPos();
/**
* Returns the number of occurrences in the list of the current leaf.
*
* @return The number of occurrences.
*
* @author Thanasis Vergoulis
*/
long getOccPosNum();
/**
* Prints the list of occurrences of the leaf.
*
* @author Thanasis Vergoulis
*/
void printOccPos();
/**
* Gets all leaves in the subtree of the node.
*
* @param leaves A vector containing pointers to the leaves (call by reference). Attention! Input
* vector has to be empty.
*
* @author Thanasis Vergoulis
*/
void getSubtreeLeaves(vector<STnode*>& leaves);
/**
* Gets all occurrences in the subtree of the node.
*
* @param occs A vector containing pointers to the occurrences (call by reference). Attention! Inpit
* vector has to be empty.
*
* @author Thanasis Vergoulis
*/
void getSubtreeOccs(vector<OccPos*>& occs);
/**
* Updates the value of _occs_num of the current node.
*
* @author Thanasis Vergoulis
*/
void updateSubtreeOccNum();
/**
* Get the number of occurrences in the subtree below the node
* @return the _occs_num variable
*/
long getOccsNum() const;
private:
//All variables are explained in the javadoc comments of the STnode class.
long _str_id;
STnode* _parent;
STnode* _children;
STnode* _right_sibling;
long _in_label_start;
long _in_label_end;
OccPos* _occ_positions;
long _occs_num;
};
#endif /* STNODE_H*/