3 unsigned int zhu( char **text
, char **pattern
, int m
, int n
, int version
)
5 /* Huge optimization instead of unsigned int B */
8 double *text2
= ( double* ) malloc( n
* n
* sizeof( double ));
11 printf("Failed to allocate array!\n");
15 double *pattern2
= ( double* ) malloc( m
* sizeof( double ));
17 if( pattern2
== NULL
) {
18 printf("Failed to allocate array!\n");
22 unsigned int i
, j
, k
, l
= 0, matches
;
24 /* Reduce text to 1d and calculate hash */
25 for( k
= 0; k
< n
- m
+ 1; k
++ )
26 for( j
= 0; j
< n
; j
++, l
++ ) {
29 for( i
= 0 + k
; i
< m
+ k
; i
++ )
30 text2
[l
] = text2
[l
] * B
+ text
[i
][j
] % Q
;
33 /* Reduce pattern to 1d and calculate hash */
34 for( j
= 0; j
< m
; j
++ ) {
37 for( i
= 0; i
< m
; i
++ )
38 pattern2
[j
] = pattern2
[j
] * B
+ pattern
[i
][j
] % Q
;
42 matches
= search_kmp( text2
, pattern2
, m
, n
);
45 matches
= search_bm( text2
, pattern2
, m
, n
);