diff options
author | Bryan Newbold <bnewbold@robocracy.org> | 2017-03-03 00:56:40 -0800 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2017-03-03 00:56:40 -0800 |
commit | fd5f104f287427fee885583bc398c137674e6af0 (patch) | |
tree | 151d1875fdbbc52fd992f53ee197f7070c5f73d1 /differ.c | |
parent | 90889a692076f2c62486607d0354e0fca52364bc (diff) | |
download | scm-upstream.tar.gz scm-upstream.zip |
New upstream version 5f2upstream/5f2upstream
Diffstat (limited to 'differ.c')
-rwxr-xr-x[-rw-r--r--] | differ.c | 109 |
1 files changed, 62 insertions, 47 deletions
@@ -23,6 +23,15 @@ #include "scm.h" +#ifdef __x86_64 +# define I32 int +#else +# define I32 long +#endif +/* Currently A:fixZ32b are actually A:fixZ64b. Remove next line when + this gets fixed. */ +#define I32 long + SCM_EXPORT SCM array_dims P((SCM ra)); typedef int (*int_function) (); @@ -33,19 +42,19 @@ typedef struct { int_function array_refs_revEql_P; } fp_procs; -int fp_compare(int *fp,int fpoff,int *cc,void *a,int m,void *b,int n,int_function array_refsEql_P,int p_lim); +int fp_compare(I32 *fp,int fpoff,I32 *cc,void *a,int m,void *b,int n,int_function array_refsEql_P,int p_lim); -int fp_run(int *fp,int fpoff,int k,void *a,int m,void *b,int n,int_function array_refsEql_P,int *cc,int p); +int fp_run(I32 *fp,int fpoff,int k,void *a,int m,void *b,int n,int_function array_refsEql_P,I32 *cc,int p); -int diff_mid_split(int n,int *rr,int *cc,int cost); +int diff_mid_split(int n,I32 *rr,I32 *cc,int cost); -void fp_init(int *fp,int fpoff,int fill,int mindx,int maxdx); +void fp_init(I32 *fp,int fpoff,int fill,int mindx,int maxdx); -int diff_divide_and_conquer(int *fp,int fpoff,int *ccrr,void *a,int start_a,int end_a,void *b,int start_b,int end_b,int *edits,int edx,int epo,fp_procs *procs,int p_lim); +int diff_divide_and_conquer(I32 *fp,int fpoff,I32 *ccrr,void *a,int start_a,int end_a,void *b,int start_b,int end_b,I32 *edits,int edx,int epo,fp_procs *procs,int p_lim); -int diff2et(int *fp,int fpoff,int *ccrr,void *a,int start_a,int end_a,void *b,int start_b,int end_b,int *edits,int edx,int epo,fp_procs *procs,int p_lim); +int diff2et(I32 *fp,int fpoff,I32 *ccrr,void *a,int start_a,int end_a,void *b,int start_b,int end_b,I32 *edits,int edx,int epo,fp_procs *procs,int p_lim); -int diff2ez(int *fp,int fpoff,int *ccrr,void *a,int start_a,int end_a,void *b,int start_b,int end_b,int *edits,int edx,int epo,fp_procs *procs,int p_lim); +int diff2ez(I32 *fp,int fpoff,I32 *ccrr,void *a,int start_a,int end_a,void *b,int start_b,int end_b,I32 *edits,int edx,int epo,fp_procs *procs,int p_lim); void check_cost(unsigned char *name,int est,int cost); @@ -53,11 +62,11 @@ SCM_EXPORT SCM diff2edits P((SCM Edits, SCM Fp, SCM Args)); SCM_EXPORT SCM diff2editlen P((SCM Fp, SCM A, SCM Args)); -# define MAX(a,b) (a<b ? b : a) -# define MIN(a,b) (a>b ? b : a) +#define MAX(a,b) (a<b ? b : a) +#define MIN(a,b) (a>b ? b : a) -long *long_subarray(ra, start, end) - long *ra; int start, end; +I32 *long_subarray(ra, start, end) + I32 *ra; int start, end; { return &(ra[start]); } @@ -72,36 +81,36 @@ char *char_subarray(ra, start, end) return &(ra[start]); } -long long_array_refsEql_P(a, x, m, b, y, n) - long *a; int x, m; long *b; int y, n; +int long_array_refsEql_P(a, x, m, b, y, n) + I32 *a; int x, m; I32 *b; int y, n; { return (a[x])==(b[y]); } -long long_array_refs_revEql_P(a, x, m, b, y, n) - long *a; int x, m; long *b; int y, n; +int long_array_refs_revEql_P(a, x, m, b, y, n) + I32 *a; int x, m; I32 *b; int y, n; { /* if (x > m) printf("long x(%d) > m(%d)\n", x, m); */ /* if (y > n) printf("long y(%d) > n(%d)\n", y, n); */ return a[(m)-(x)-1]==b[(n)-(y)-1]; } -short short_array_refsEql_P(a, x, m, b, y, n) +int short_array_refsEql_P(a, x, m, b, y, n) short *a; int x, m; short *b; int y, n; { return (a[x])==(b[y]); } -short short_array_refs_revEql_P(a, x, m, b, y, n) +int short_array_refs_revEql_P(a, x, m, b, y, n) short *a; int x, m; short *b; int y, n; { /* if (x > m) printf("short x(%d) > m(%d)\n", x, m); */ /* if (y > n) printf("short y(%d) > n(%d)\n", y, n); */ return a[(m)-(x)-1]==b[(n)-(y)-1]; } -char char_array_refsEql_P(a, x, m, b, y, n) +int char_array_refsEql_P(a, x, m, b, y, n) char *a; int x, m; char *b; int y, n; { return (a[x])==(b[y]); } -char char_array_refs_revEql_P(a, x, m, b, y, n) +int char_array_refs_revEql_P(a, x, m, b, y, n) char *a; int x, m; char *b; int y, n; { /* if (x > m) printf("char x(%d) > m(%d)\n", x, m); */ @@ -110,16 +119,22 @@ char char_array_refs_revEql_P(a, x, m, b, y, n) } fp_procs long_procs = - {long_subarray, long_array_refsEql_P, long_array_refs_revEql_P}; + {long_subarray, + long_array_refsEql_P, + long_array_refs_revEql_P}; fp_procs short_procs = - {short_subarray, short_array_refsEql_P, short_array_refs_revEql_P}; + {short_subarray, + short_array_refsEql_P, + short_array_refs_revEql_P}; fp_procs char_procs = - {char_subarray, char_array_refsEql_P, char_array_refs_revEql_P}; + {char_subarray, + char_array_refsEql_P, + char_array_refs_revEql_P}; int fp_compare(fp, fpoff, cc, a, m, b, n, array_refsEql_P, p_lim) - int *fp; + I32 *fp; int fpoff; - int *cc; + I32 *cc; void *a; int m; void *b; @@ -170,7 +185,7 @@ L_loop: /* Returns furthest y reached. */ int fp_run(fp, fpoff, k, a, m, b, n, array_refsEql_P, cc, p) - int *fp; + I32 *fp; int fpoff; int k; void *a; @@ -178,7 +193,7 @@ int fp_run(fp, fpoff, k, a, m, b, n, array_refsEql_P, cc, p) void *b; int n; int_function array_refsEql_P; - int *cc; + I32 *cc; int p; { int cost = (k)+(p)+(p); @@ -212,8 +227,8 @@ L_snloop: int diff_mid_split(n, rr, cc, cost) int n; - int *rr; - int *cc; + I32 *rr; + I32 *cc; int cost; { { @@ -234,7 +249,7 @@ L_loop: void fp_init(fp, fpoff, fill, mindx, maxdx) - int *fp; + I32 *fp; int fpoff; int fill; int mindx; @@ -257,16 +272,16 @@ void fp_init(fp, fpoff, fill, mindx, maxdx) /* EPO is insert/delete polarity (+1 or -1) */ int diff_divide_and_conquer(fp, fpoff, ccrr, a, start_a, end_a, b, start_b, end_b, edits, edx, epo, procs, p_lim) - int *fp; + I32 *fp; int fpoff; - int *ccrr; + I32 *ccrr; void *a; int start_a; int end_a; void *b; int start_b; int end_b; - int *edits; + I32 *edits; int edx; int epo; fp_procs *procs; @@ -277,8 +292,8 @@ int diff_divide_and_conquer(fp, fpoff, ccrr, a, start_a, end_a, b, start_b, end_ int len_a = (end_a)-(start_a); { int tcst = (p_lim)+(p_lim)+((len_b)-(len_a)); - int *cc = &(ccrr[0]); - int *rr = &(ccrr[(len_b)+1]); + I32 *cc = &(ccrr[0]); + I32 *rr = &(ccrr[(len_b)+1]); int m2 = (end_a)-(mid_a); int m1 = (mid_a)-(start_a); fp_init(cc, 0, (len_a)+(len_b), 0, len_b); @@ -289,8 +304,8 @@ int diff_divide_and_conquer(fp, fpoff, ccrr, a, start_a, end_a, b, start_b, end_ fp_compare(fp, fpoff, rr, procs->subarray(a, mid_a, end_a), m2, procs->subarray(b, start_b, end_b), len_b, procs->array_refs_revEql_P, MIN(p_lim, len_a)); { int b_splt = diff_mid_split(len_b, rr, cc, tcst); - int est_c = cc[b_splt]; - int est_r = rr[(len_b)-(b_splt)]; + I32 est_c = cc[b_splt]; + I32 est_r = rr[(len_b)-(b_splt)]; check_cost("cc", est_c, diff2et(fp, fpoff, ccrr, a, start_a, mid_a, b, start_b, (start_b)+(b_splt), edits, edx, epo, procs, ((est_c)-((b_splt)-((mid_a)-(start_a))))/2)); check_cost("rr", est_r, diff2et(fp, fpoff, ccrr, a, mid_a, end_a, b, (start_b)+(b_splt), end_b, edits, (est_c)+(edx), epo, procs, ((est_r)-(((len_b)-(b_splt))-((end_a)-(mid_a))))/2)); return (est_c)+(est_r); @@ -301,16 +316,16 @@ int diff_divide_and_conquer(fp, fpoff, ccrr, a, start_a, end_a, b, start_b, end_ /* Trim; then diff sub-arrays; either one longer. Returns edit-length */ int diff2et(fp, fpoff, ccrr, a, start_a, end_a, b, start_b, end_b, edits, edx, epo, procs, p_lim) - int *fp; + I32 *fp; int fpoff; - int *ccrr; + I32 *ccrr; void *a; int start_a; int end_a; void *b; int start_b; int end_b; - int *edits; + I32 *edits; int edx; int epo; fp_procs *procs; @@ -351,16 +366,16 @@ int diff2et(fp, fpoff, ccrr, a, start_a, end_a, b, start_b, end_b, edits, edx, e /* Diff sub-arrays, A not longer than B. Returns edit-length */ int diff2ez(fp, fpoff, ccrr, a, start_a, end_a, b, start_b, end_b, edits, edx, epo, procs, p_lim) - int *fp; + I32 *fp; int fpoff; - int *ccrr; + I32 *ccrr; void *a; int start_a; int end_a; void *b; int start_b; int end_b; - int *edits; + I32 *edits; int edx; int epo; fp_procs *procs; @@ -472,7 +487,7 @@ void* array2addr(RA, prot, pos, s_name) { ASRTER(BOOL_T==arrayp(RA, UNDEFINED) && array_prot(RA)==prot, RA, pos, s_name); - return (void*)scm_addr(cons(RA, list_of_0), s_name); + return scm_addr(cons(RA, list_of_0), s_name); } /* A not longer than B (M <= N) */ @@ -482,10 +497,10 @@ SCM diff2edits(Edits, Fp, Args) SCM Edits, Fp, Args; /* Ccrr, A, B; */ { SCM aprot, bprot; - int *edits; + I32 *edits; int est; - int *fp; - int *ccrr; + I32 *fp; + I32 *ccrr; void *a, *b; int m, n; fp_procs *procs; @@ -525,7 +540,7 @@ SCM diff2editlen(Fp, A, Args) fp_procs *procs; int p_lim; int m, n; - int *fp; + I32 *fp; void *a, *b; ASRTER(2==ilength(Args), Args, WNA, s_d2el); fp = array2addr(Fp, MAKINUM(-32), ARG1, s_d2el); |