3 int naive3( char **text
, char **pattern
, int m
, int n
, int textrow
, int textcolumn
, int patternrow
)
7 for ( i
= textcolumn
; i
< n
- m
+ 1; i
++ ) {
11 for ( j
= 0; j
< m
; j
++ ) {
13 if ( pattern
[patternrow
][j
] == text
[textrow
][k
] )
23 /* No match found on this row */
27 int naive3b( char **text
, char **pattern
, int m
, int n
, int textrow
, int textcolumn
, int patternrow
)
31 for ( j
= 0; j
< m
; j
++ ) {
33 if ( pattern
[patternrow
][j
] == text
[textrow
][textcolumn
] )
38 /* If reached through here, report success */
42 unsigned int bird2( char **text
, char **pattern
, int m
, int n
)
44 /* x and y can be -1 */
47 unsigned int i
, row
, matches
= 0;
50 for ( row
= 0; row
< n
- m
+ 1; row
++ ) {
54 /* Iterate through results on the same row */
57 x
= naive3 ( text
, pattern
, m
, n
, row
, x
, 0 );
59 /* If a row is found, check the m - 1 rows underneath it for matches */
62 for ( i
= 1; i
< m
; i
++) {
63 /* Optimization: instead of checking against n chars on
64 subsequent rows, just check against the next m chars after x without sliding the window */
65 if ( naive3b ( text
, pattern
, m
, n
, row
+ i
, x
, i
) == -1 )
71 /* After each attempt,increase the counter +1 */