-
Notifications
You must be signed in to change notification settings - Fork 0
/
BWT.h
61 lines (56 loc) · 1.3 KB
/
BWT.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
#pragma once
class BWT
{
public:
BWT();
~BWT();
string Read_Reference(string filename);
vector<string> Read_Subs(string filename);
void preprocess();
void preprocess2();
vector<int> search(string sub);
void unexactsearch(string sub, float e);
int Occ(int r, char c);
int LFC(int r, char c);
int getC(char c);
int editDis(string c1, string c2);
void run();
string T;
vector<int> SA;
vector<unordered_map<char, int>> Checkpoint;
unordered_map<char, int> C;
unordered_map<char, char> toNext;
vector<string> Matrix;
string SAstring(int i)
{
return T.substr(SA[i], SA.size() - SA[i]);
}
//每一趟选一个基准数,找出比它大的和比它小的个数,就能确定它的位置!
int partition(int low, int high) {
string base = SAstring(high);
int tail = low - 1;
for (int i = low; i < high; i++) // 遍历基准以外的其他元素
{
if (SAstring(i) <= base) // 把小于等于基准的元素放到前一个子数组中
{
tail++;
if (tail == i) continue;
else
{
swap(SA[tail], SA[i]);
}
}
}
swap(SA[tail + 1], SA[high]);
return tail + 1;
}
void QuickSort(int low, int high) {
if (high < low) return;
int Index = partition(low, high); //将表一分为二
QuickSort(low, Index - 1); //递归对低子表递归排序
QuickSort(Index + 1, high);
}
private:
string BWTS;
//vector<string> Index2;
};