From: Ben Pfaff Date: Sat, 20 Dec 2003 05:35:51 +0000 (+0000) Subject: Fri Dec 19 21:30:24 2003 Ben Pfaff X-Git-Tag: v0.4.0~413 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=808aee8f2975b80004c861258957baf2a9c8f00b;p=pspp-builds.git Fri Dec 19 21:30:24 2003 Ben Pfaff * sort.c: (compare_case_lists) Rewrite. --- diff --git a/src/ChangeLog b/src/ChangeLog index a5aa9c09..9e3a00f8 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +Fri Dec 19 21:30:24 2003 Ben Pfaff + + * sort.c: (compare_case_lists) Rewrite. + Fri Dec 19 16:44:22 2003 Ben Pfaff * quicksort.c: Removed (not used). diff --git a/src/sort.c b/src/sort.c index 515793d3..c77d8462 100644 --- a/src/sort.c +++ b/src/sort.c @@ -215,13 +215,16 @@ do_internal_sort (int separate) return 0; } -/* Compares the NV_SORT variables in V_SORT[] between the `case_list's - at _A and _B, and returns a strcmp()-type result. */ +/* Compares the NV_SORT variables in V_SORT[] between the + `case_list's at A and B, and returns a strcmp()-type + result. */ static int -compare_case_lists (const void *pa, const void *pb) +compare_case_lists (const void *a_, const void *b_) { - struct case_list *a = *(struct case_list **) pa; - struct case_list *b = *(struct case_list **) pb; + struct case_list *const *pa = a_; + struct case_list *const *pb = b_; + struct case_list *a = *pa; + struct case_list *b = *pb; struct variable *v; int result = 0; int i; @@ -232,27 +235,21 @@ compare_case_lists (const void *pa, const void *pb) if (v->type == NUMERIC) { - if (approx_ne (a->c.data[v->fv].f, b->c.data[v->fv].f)) - { - result = (a->c.data[v->fv].f > b->c.data[v->fv].f) ? 1 : -1; - break; - } + double af = a->c.data[v->fv].f; + double bf = b->c.data[v->fv].f; + + result = af < bf ? -1 : af > bf; } else - { - result = memcmp (a->c.data[v->fv].s, b->c.data[v->fv].s, v->width); - if (result != 0) - break; - } - } + result = memcmp (a->c.data[v->fv].s, b->c.data[v->fv].s, v->width); - if (v->p.srt.order == SRT_ASCEND) - return result; - else - { - assert (v->p.srt.order == SRT_DESCEND); - return -result; + if (result != 0) + break; } + + if (v->p.srt.order == SRT_DESCEND) + result = -result; + return result; } /* External sort. */