-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathskip.h
More file actions
44 lines (40 loc) · 1.21 KB
/
Copy pathskip.h
File metadata and controls
44 lines (40 loc) · 1.21 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
//
// Created by pc on 5/30/2024.
//
#ifndef ESTIMATINGSTRINGPATTERNALGORITHMS_SKIP_H
#define ESTIMATINGSTRINGPATTERNALGORITHMS_SKIP_H
#include "include/define.h"
#include "include/main_header.h"
#include "include/AUTOMATON.h"
#include "Algorithm.h"
class skip : public Algorithm {
public:
const char* name() const override {
return "Skip";
}
int search(unsigned char *x, int m, unsigned char *y, int n) override {
int i, j, count, h, k;
List ptr, z[SIGMA];
memset(z, 0, SIGMA*sizeof(List));
for (i = 0; i < m; ++i) {
ptr = (List)malloc(sizeof(struct _cell));
if (ptr == NULL)
error("SKIP");
ptr->element = i;
ptr->next = z[x[i]];
z[x[i]] = ptr;
}
count = 0;
/* Searching */
for (j = m - 1; j < n; j += m)
for (ptr = z[y[j]]; ptr != NULL; ptr = ptr->next)
if((j-ptr->element) <= n-m) {
k = 0;
h = j-ptr->element;
while(k<m && x[k]==y[h+k]) k++;
if(k>=m) count++;
}
return count;
}
};
#endif //ESTIMATINGSTRINGPATTERNALGORITHMS_SKIP_H