-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbxs.h
More file actions
64 lines (58 loc) · 1.73 KB
/
Copy pathbxs.h
File metadata and controls
64 lines (58 loc) · 1.73 KB
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
//
// Created by pc on 5/30/2024.
//
#ifndef ESTIMATINGSTRINGPATTERNALGORITHMS_BXS_H
#define ESTIMATINGSTRINGPATTERNALGORITHMS_BXS_H
#endif //ESTIMATINGSTRINGPATTERNALGORITHMS_BXS_H
#include "Algorithm.h"
#include "include/define.h"
#define Q 1
class bxs : public Algorithm {
public:
const char* name() const override {
return "BXS";
}
int search(unsigned char *x, int m, unsigned char *y, int n) override {
unsigned int B[SIGMA], D, set;
int i, j, first, k, mm, sh, m1, count;
if (m < Q) return -1;
if (m>128){
KMP kmp;
return kmp.search(x, m, y, n);
}
//int larger = m>WORD? 1:0;
//if(larger) m = WORD;
int w = WORD, mq1 = m - Q + 1, nq1 = n - Q + 1;
if (w > m) w = m;
unsigned int mask = 1 << (w - 1);
/* Preprocessing */
count = 0;
set = 1;
for (i = 0; i < SIGMA; i++) B[i] = 0;
for (i = m - 1; i >= 0; i--) {
B[x[i]] |= set;
set <<= 1;
if (set == 0) set = 1;
}
/* Searching */
for (i = mq1 - 1; i < nq1; i += mq1) {
D = B[y[i]];
if (D) {
j = i;
first = i - mq1;
do {
j--;
if (D >= mask) {
if (j - first) i = j;
else {
for (k = m; y[first + k] == x[k - 1] && (k); k--);
if (k == 0) count++;
}
D = ((D << 1) | 1) & B[y[j]];
} else D = (D << 1) & B[y[j]];
} while (D && j > first);
}
}
return count;
}
};