From: Martin Mares Date: Sat, 8 Sep 2007 17:51:30 +0000 (+0200) Subject: Changed the interface of the array sorter: the buffer and hash_bits parameters X-Git-Tag: holmes-import~506^2~13^2~39 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=1f1ccf1786a62973de953e3f5c43392ad485770d;p=libucw.git Changed the interface of the array sorter: the buffer and hash_bits parameters are passed only if hashing is enabled. --- diff --git a/lib/sorter/array.h b/lib/sorter/array.h index aeb7c64c..0f18741b 100644 --- a/lib/sorter/array.h +++ b/lib/sorter/array.h @@ -34,13 +34,13 @@ * radix-sorting. * * After including this file, a function - * ASORT_KEY_TYPE *ASORT_PREFIX(sort)(ASORT_KEY_TYPE *array, uns num_elts, ASORT_KEY_TYPE *buf, uns hash_bits) + * ASORT_KEY_TYPE *ASORT_PREFIX(sort)(ASORT_KEY_TYPE *array, uns num_elts [, ASORT_KEY_TYPE *buf, uns hash_bits]) * is declared and all parameter macros are automatically undef'd. Here `buf' is an * auxiliary buffer of the same size as the input array, required whenever radix * sorting should be used, and `hash_bits' is the number of significant bits returned * by the hash function. If the buffer is specified, the sorting function returns either * a pointer to the input array or to the buffer, depending on where the result is stored. - * If you do not use hashing, these parameters should be NULL and 0, respectively. + * If you do not use hashing, these parameters should be omitted. */ #include "lib/sorter/common.h" @@ -284,17 +284,21 @@ static void Q(radix_split)(void *src_ptr, void *dest_ptr, uns num_elts, uns *ptr #endif -static Q(key) *Q(sort)(Q(key) *array, uns num_elts, Q(key) *buffer, uns hash_bits) +static Q(key) *Q(sort)(Q(key) *array, uns num_elts +#ifdef ASORT_HASH + , Q(key) *buffer, uns hash_bits +#endif + ) { struct asort_context ctx = { .array = array, - .buffer = buffer, .num_elts = num_elts, - .hash_bits = hash_bits, .elt_size = sizeof(Q(key)), .quicksort = Q(quicksort), .quicksplit = Q(quicksplit), #ifdef ASORT_HASH + .buffer = buffer, + .hash_bits = hash_bits, .radix_count = Q(radix_count), .radix_split = Q(radix_split), .radix_bits = ASORT_RADIX_BITS, diff --git a/lib/sorter/s-fixint.h b/lib/sorter/s-fixint.h index d901a064..9787a682 100644 --- a/lib/sorter/s-fixint.h +++ b/lib/sorter/s-fixint.h @@ -72,11 +72,9 @@ static int P(internal)(struct sort_context *ctx, struct sort_bucket *bin, struct stk_fsize(n * P(internal_workspace)())); timestamp_t timer; init_timer(&timer); - buf = P(array_sort)(buf, n, + buf = P(array_sort)(buf, n #ifdef SORT_INTERNAL_RADIX - workspace, bin->hash_bits -#else - NULL, 0 + , workspace, bin->hash_bits #endif ); ctx->total_int_time += get_timer(&timer); diff --git a/lib/sorter/s-internal.h b/lib/sorter/s-internal.h index 23f14e52..ef2da240 100644 --- a/lib/sorter/s-internal.h +++ b/lib/sorter/s-internal.h @@ -172,11 +172,9 @@ static int P(internal)(struct sort_context *ctx, struct sort_bucket *bin, struct stk_fsize((byte*)ctx->big_buf + bufsize - end)); timestamp_t timer; init_timer(&timer); - item_array = P(array_sort)(item_array, count, + item_array = P(array_sort)(item_array, count #ifdef SORT_INTERNAL_RADIX - workspace, bin->hash_bits -#else - NULL, 0 + , workspace, bin->hash_bits #endif ); ctx->total_int_time += get_timer(&timer); diff --git a/lib/sorter/sort-test.c b/lib/sorter/sort-test.c index 92f8d9b7..71c6a12f 100644 --- a/lib/sorter/sort-test.c +++ b/lib/sorter/sort-test.c @@ -468,7 +468,7 @@ static int s5_presort(struct fastbuf *dest, void *buf, size_t bufsize) n++; if (!n) return 0; - s5p_sort(a, n, NULL, 0); + s5p_sort(a, n); uns i = 0; while (i < n) {