-
Notifications
You must be signed in to change notification settings - Fork 5
/
kmp.c
53 lines (35 loc) · 828 Bytes
/
kmp.c
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
/* kmp.c : longest extension functions */
#include <stdlib.h>
#include "defs.h"
int *computeLIx (char *pattern, int patLen, int dir, int maxPerBnd)
/* Roman's modification of computeLIe */
{
int *LIx = malloc (maxPerBnd*sizeof(int));
int i=1 ;
while(i<maxPerBnd)
{
int j = 0 ;
while ( i+j < patLen &&
pattern[dir*j] == pattern[dir*(i+j)] )
j++ ;
LIx[i]=j ;
i++;
}
return LIx ;
}
int *computeLOx (char *pattern, int patLen, int dir, int maxPerBnd)
/* Roman's modification of computeLOe */
{
int *LOx = malloc (maxPerBnd*sizeof(int));
int i=1 ;
while(i<maxPerBnd)
{
int j = 0 ;
while ( j < patLen &&
pattern[dir*j] == pattern[dir*(j-i)] )
j++ ;
LOx[i]=j ;
i++;
}
return LOx ;
}