All algorithms should return the number of matches
[2dmatching.git] / zhu.c
blobd1ef352129130d14ec561ba2a87f61e1852a2092
1 #include "code.h"
3 unsigned int zhu( int version )
5 unsigned int i = 0, j = 0, k = 0, matches;
7 /* Huge optimization instead of unsigned int B */
8 #define B 128
10 #define limit n * n - (n * ( m - 1 ))
12 /* Reduce text to 1d and calculate hash */
13 for( k = 0; k < limit; k = n + k )
14 for( j = 0 + k; j < n + k; j++ ) {
15 text2[j] = 0;
17 for( i = 0; i < m; i++ )
18 text2[j] = text2[j] * B + text[i][j] % Q;
21 /* Reduce pattern to 1d and calculate hash */
22 for( j = 0; j < m; j++ ) {
23 pattern2[j] = 0;
25 for( i = 0; i < m; i++ )
26 pattern2[j] = ( pattern2[j] * B ) + pattern[i][j] % Q;
29 if ( version == 1 )
30 matches = search_kmp();
32 else
33 matches = search_bm();
35 return matches;