#endif
+#define ELEMENT char
+#define EQUAL(x,y) ((x) == (y))
+#define OFFSET int
+
+/* Before including this file, you need to define:
+ ELEMENT The element type of the sequences being compared.
+ EQUAL A two-argument macro that tests two elements for
+ equality.
+ OFFSET A signed integer type sufficient to hold the
+ difference between two indices. Usually
+ something like ssize_t. */
+
/*
* Context of comparison operation.
*/
struct string_data
{
/* The string to be compared. */
- const char *data;
+ const ELEMENT *data;
/* The length of the string to be compared. */
int data_length;
/* Vector, indexed by diagonal, containing 1 + the X coordinate of the
point furthest along the given diagonal in the forward search of the
edit matrix. */
- int *fdiag;
+ OFFSET *fdiag;
/* Vector, indexed by diagonal, containing the X coordinate of the point
furthest along the given diagonal in the backward search of the edit
matrix. */
- int *bdiag;
+ OFFSET *bdiag;
/* Edit scripts longer than this are too expensive to compute. */
- int too_expensive;
+ OFFSET too_expensive;
/* Snakes bigger than this are considered `big'. */
#define SNAKE_LIMIT 20
output. */
static void
-diag (int xoff, int xlim, int yoff, int ylim, int minimal,
+diag (OFFSET xoff, OFFSET xlim, OFFSET yoff, OFFSET ylim, OFFSET minimal,
struct partition *part, struct context *ctxt)
{
- int *const fd = ctxt->fdiag; /* Give the compiler a chance. */
- int *const bd = ctxt->bdiag; /* Additional help for the compiler. */
- const char *const xv = ctxt->string[0].data; /* Still more help for the compiler. */
- const char *const yv = ctxt->string[1].data; /* And more and more . . . */
- const int dmin = xoff - ylim; /* Minimum valid diagonal. */
- const int dmax = xlim - yoff; /* Maximum valid diagonal. */
- const int fmid = xoff - yoff; /* Center diagonal of top-down search. */
- const int bmid = xlim - ylim; /* Center diagonal of bottom-up search. */
- int fmin = fmid;
- int fmax = fmid; /* Limits of top-down search. */
- int bmin = bmid;
- int bmax = bmid; /* Limits of bottom-up search. */
- int c; /* Cost. */
+ OFFSET *const fd = ctxt->fdiag; /* Give the compiler a chance. */
+ OFFSET *const bd = ctxt->bdiag; /* Additional help for the compiler. */
+ const ELEMENT *const xv = ctxt->string[0].data; /* Still more help for the compiler. */
+ const ELEMENT *const yv = ctxt->string[1].data; /* And more and more . . . */
+ const OFFSET dmin = xoff - ylim; /* Minimum valid diagonal. */
+ const OFFSET dmax = xlim - yoff; /* Maximum valid diagonal. */
+ const OFFSET fmid = xoff - yoff; /* Center diagonal of top-down search. */
+ const OFFSET bmid = xlim - ylim; /* Center diagonal of bottom-up search. */
+ OFFSET fmin = fmid;
+ OFFSET fmax = fmid; /* Limits of top-down search. */
+ OFFSET bmin = bmid;
+ OFFSET bmax = bmid; /* Limits of bottom-up search. */
+ OFFSET c; /* Cost. */
int odd = (fmid - bmid) & 1;
/*
bd[bmid] = xlim;
for (c = 1;; ++c)
{
- int d; /* Active diagonal. */
+ OFFSET d; /* Active diagonal. */
int big_snake;
big_snake = 0;
--fmax;
for (d = fmax; d >= fmin; d -= 2)
{
- int x;
- int y;
- int oldx;
- int tlo;
- int thi;
+ OFFSET x;
+ OFFSET y;
+ OFFSET oldx;
+ OFFSET tlo;
+ OFFSET thi;
tlo = fd[d - 1],
thi = fd[d + 1];
--bmax;
for (d = bmax; d >= bmin; d -= 2)
{
- int x;
- int y;
- int oldx;
- int tlo;
- int thi;
+ OFFSET x;
+ OFFSET y;
+ OFFSET oldx;
+ OFFSET tlo;
+ OFFSET thi;
tlo = bd[d - 1],
thi = bd[d + 1];
of changes, the algorithm is linear in the strings size. */
if (c > 200 && big_snake && ctxt->heuristic)
{
- int best;
+ OFFSET best;
best = 0;
for (d = fmax; d >= fmin; d -= 2)
{
- int dd;
- int x;
- int y;
- int v;
+ OFFSET dd;
+ OFFSET x;
+ OFFSET y;
+ OFFSET v;
dd = d - fmid;
x = fd[d];
best = 0;
for (d = bmax; d >= bmin; d -= 2)
{
- int dd;
- int x;
- int y;
- int v;
+ OFFSET dd;
+ OFFSET x;
+ OFFSET y;
+ OFFSET v;
dd = d - bmid;
x = bd[d];
and report halfway between our best results so far. */
if (c >= ctxt->too_expensive)
{
- int fxybest;
- int fxbest;
- int bxybest;
- int bxbest;
+ OFFSET fxybest;
+ OFFSET fxbest;
+ OFFSET bxybest;
+ OFFSET bxbest;
/* Pacify `gcc -Wall'. */
fxbest = 0;
fxybest = -1;
for (d = fmax; d >= fmin; d -= 2)
{
- int x;
- int y;
+ OFFSET x;
+ OFFSET y;
x = fd[d] < xlim ? fd[d] : xlim;
y = x - d;
bxybest = INT_MAX;
for (d = bmax; d >= bmin; d -= 2)
{
- int x;
- int y;
+ OFFSET x;
+ OFFSET y;
x = xoff > bd[d] ? xoff : bd[d];
y = x - d;
expensive it is. */
static void
-compareseq (int xoff, int xlim, int yoff, int ylim, int minimal,
+compareseq (OFFSET xoff, OFFSET xlim, OFFSET yoff, OFFSET ylim, int minimal,
struct context *ctxt)
{
- const char *const xv = ctxt->string[0].data; /* Help the compiler. */
- const char *const yv = ctxt->string[1].data;
+ const ELEMENT *const xv = ctxt->string[0].data; /* Help the compiler. */
+ const ELEMENT *const yv = ctxt->string[1].data;
/* Slide down the bottom initial diagonal. */
while (xoff < xlim && yoff < ylim && xv[xoff] == yv[yoff])