-
Notifications
You must be signed in to change notification settings - Fork 0
/
lca.h
executable file
·60 lines (51 loc) · 1.16 KB
/
lca.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
#ifndef LCA_H
#define LCA_H
#include "suffix_tree.h"
class LCA {
int max_num_nodes;
int num_bits;
int* rightmost;
int* leftmost;
int* shifts;
int* masks;
int* I;
int* run_heads;
int* Av;
protected:
void createBitStructures();
public:
void processTree(SuffixTree& tree);
LCA(int max_nnodes){
max_num_nodes = max_nnodes;
setNumBits();
leftmost = new int [1<<num_bits];
rightmost = new int [1<<num_bits];
shifts = new int [num_bits+2];
masks = new int [num_bits+2];
I = new int [max_num_nodes+1];
run_heads = new int [max_num_nodes+1];
Av = new int [max_num_nodes+1];
createBitStructures();
}
~LCA(){
delete [] leftmost;
delete [] rightmost;
delete [] shifts;
delete [] masks;
delete [] I;
delete [] run_heads;
delete [] Av;
}
void setNumBits(){
num_bits = 0;
int val = max_num_nodes;
while (val > 0){
num_bits++;
val >>= 1;
}
}
Node* lca(SuffixTree& tree, Node* x, Node* y);
Node* lca(SuffixTree& tree, int sfx_idx_1, int sfx_idx_2);
int longestPrefix(SuffixTree& tree, int sfx_idx_1, int sfx_idx_2);
};
#endif