All algorithms should return the number of matches
[2dmatching.git] / bird.c
blob30b46d2631742210d48cbc57967edb6503b9b026
1 #include "code.h"
3 unsigned int bird()
4 {
5 /* x and y can be -1 */
6 int x, y;
8 unsigned int i, row, matches = 0;
10 /* Iterate rows */
11 for ( row = 0; row < n - m + 1; row++ ) {
13 x = 0;
15 /* Iterate through results on the same row */
16 while ( x != -1 ) {
18 x = aho( row, x, 0, n - m );
20 /* If a row is found, check the m - 1 rows underneath it for matches */
21 if ( x != -1 ) {
23 for ( i = 1; i < m; i++) {
24 /* Optimization: instead of checking against n chars on
25 subsequent rows, just check against the next m chars after x */
26 y = aho( row + i, x, i, x + m );
28 if ( y != x )
29 break;
31 /* If we reached to the final line above x without breaking, we have a match */
32 else if ( i == m -1)
33 matches++;
35 /* After each attempt,increase the counter + 1 */
36 x++;
40 return matches;