3 int naive2( char **text
, char **pattern
, int m
, int n
, int textrow
, int textcolumn
, int patternrow
)
7 for(i
= textcolumn
; i
< n
- m
; i
++) {
11 for(j
= 0; j
< m
; j
++) {
13 if( pattern
[patternrow
][j
] == text
[textrow
][k
])
27 /* No match found on this row */
31 unsigned int baeza2( char **text
, char **pattern
, int m
, int n
)
33 int x
, y
, i
, j
, row
, matches
= 0;
35 /* Iterate every m rows (first check lines 0 to m - 1) */
36 for ( row
= m
- 1; row
< n
; row
+= m
) {
38 /* Search the same row for occurences of the different lines of the pattern */
39 for ( i
= 0; i
< m
; i
++ ) {
41 /* In each row start searching from the begining */
46 /* Check text's row against each pattern's row */
47 x
= naive2( text
, pattern
, m
, n
, row
, x
, i
);
49 /* If a row is not found procceed to the next row */
52 /* If there is a match at i = 3, check vertically the text above for i = 0-2 and below for 4-m*/
54 /* Check lines above the current */
55 for ( j
= 0; j
< i
; j
++ ) {
56 y
= naive2( text
, pattern
, m
, n
, row
- i
+ j
, x
, j
);
62 /* Check lines below the current */
63 for ( j
= 1; j
< m
- i
; j
++ ) {
65 /* Avoid crashing when x = n or n-1 */
69 y
= naive2( text
, pattern
, m
, n
, row
+ j
, x
, i
+ j
);
75 /* If we reached here we should have a match */
78 /* If a mismatch is found, don't bother searching for the other y lines */
81 /* Now increase counter to continue searching on the same row */