// bords.c
// << Algorithmique du texte >>
// Maxime Crochemore, Christophe Hancart et Thierry Lecroq
// Vuibert, 2001.
#include <stdio.h>
#include "chl.h"
int *bords(Mot x, Longueur m) {
int i, j, *bord;
bord = (int *)malloc(m*sizeof(int));
if (bord == NULL) error("bords");
i = 0;
for (j = 1; j <= m - 1; ++j) {
bord[j - 1] = i;
while (i >= 0 && x[j] != x[i])
if (i == 0)
i = -1;
else
i = bord[i - 1];
++i;
}
bord[m - 1] = i;
return(bord);
}