]> mj.ucw.cz Git - libucw.git/commitdiff
Changed the interface of the array sorter: the buffer and hash_bits parameters
authorMartin Mares <mj@ucw.cz>
Sat, 8 Sep 2007 17:51:30 +0000 (19:51 +0200)
committerMartin Mares <mj@ucw.cz>
Sat, 8 Sep 2007 17:51:30 +0000 (19:51 +0200)
are passed only if hashing is enabled.

lib/sorter/array.h
lib/sorter/s-fixint.h
lib/sorter/s-internal.h
lib/sorter/sort-test.c

index aeb7c64c380bc038b1a1dda0e414109913dfc379..0f18741b451d1f4a1223c5817b29ac78a6726dcb 100644 (file)
  *                     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,
index d901a064d34d4881a8393835b90e652b81f37335..9787a682010b1a8c88659acd4eb4543a6daca8bc 100644 (file)
@@ -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);
index 23f14e52b2cc8ea40e574ace9b41ad99cf8c373a..ef2da2402958cfa62bfdac3a69d575390ce7e0a8 100644 (file)
@@ -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);
index 92f8d9b762d861574d9b13972affe5e8a15f0432..71c6a12ff75790b82bfeb6d2c216352fe94ea6fa 100644 (file)
@@ -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)
     {