#include <stdio.h>
#include <stdlib.h>

#include "matrix.h"
#include "apl.h"

void apl_find_repeating(int (*a)[cols], int rows, struct array *res)
{
    int i;
    char *seen;

    if (rows < 2)
        return;

    seen = calloc(rows, 1);
    if (!seen) {
        fprintf(stderr, "apl_find_repeating: out of memory\n");
        exit(1);
    }

    for (i = 0; i < rows - 1; i++)
        if (array_compare(a[i], a[i+1], min) == 0) {
            seen[a[i][min]] = 1;
            seen[a[i+1][min]] = 1;
        }

    for (i = 0; i < rows; i++)
        if (seen[i])
            array_push(res, i);

    free(seen);
}
