-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapprox_shor.h
executable file
·66 lines (53 loc) · 1.89 KB
/
approx_shor.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
#ifndef APPROX_SHOR_H
#define APPROX_SHOR_H
#include "libraries/so.h"
#include "libraries/lev.h"
#include "libraries/approx_utils.h"
#include "approx_cf.h"
#ifndef K_DIFF
#define K_DIFF 2
#endif
namespace approx_shor {
void print_result(double search_time, long ver_count, long matches, long text_file_size, long pattern_size, long k_diff
) {
double inmb = text_file_size / 1000.0 / 1000.0;
printf("%ld\t", k_diff); // k diff
printf("%ld\t", text_file_size); // data information
printf("%ld\t%ld\t", ver_count, matches); // search information
printf("%lf\t", search_time); // times
printf("%f", inmb/search_time); // speed
printf("\n");
}
struct SO_verif_approx_args_s {
int div;
int pattern_size;
};
void cf1_verif_lev_with_offset(const uchar *p, int m, const uchar *t, int n, int pos, int k, void *args) {
int levk = levenshtein<const uchar*>(p, t+pos, m, m);
if(levk <= k ) {
indexes.insert(pos + (* (int *)args) );
}
}
void SO_verif_cf_lev(const uchar *p, int m, const uchar *t, int n, int pos, void *args) {
int position = pos - ((SO_verif_approx_args_s*)args)->div - K_DIFF;
cf::cf1<cf1_verif_lev_with_offset>(
p - ((SO_verif_approx_args_s*)args)->div,
((SO_verif_approx_args_s*)args)->pattern_size,
t + position,
((SO_verif_approx_args_s*)args)->pattern_size + 2 * K_DIFF,
K_DIFF,
(void*)(&position)
);
}
void SO_verif_exact(const uchar *p, int m, const uchar *t, int n, int pos, void *args) {
int position = pos - ((SO_verif_approx_args_s*)args)->div;
if (memcmp(p, t + position, ((SO_verif_approx_args_s*)args)->pattern_size) == 0) {
indexes.insert(pos);
};
}
void SO_verif_nothing(const uchar *p, int m, const uchar *t, int n, int pos, void *args) {
int position = pos - ((SO_verif_approx_args_s*)args)->div;
indexes.insert(position);
}
}
#endif