* ASORT_PREFIX(x) [*] add a name prefix (used on all global names
* defined by the sorter)
* ASORT_KEY_TYPE [*] data type of a single array entry key
- * ASORT_LT(x,y) x < y for ASORT_TYPE (default: "x<y")
+ * ASORT_LT(x,y) x < y for ASORT_KEY_TYPE (default: "x<y")
* ASORT_HASH(x) a monotone hash function (safisfying hash(x) < hash(y) => x<y)
* ASORT_LONG_HASH hashes are 64-bit numbers (default is 32 bits)
*
* 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"
#endif
#ifndef ASORT_RADIX_BITS
-#define ASORT_RADIX_BITS 12 // FIXME: Tune automatically?
+#define ASORT_RADIX_BITS CONFIG_UCW_RADIX_SORTER_BITS
#endif
#define ASORT_RADIX_MASK ((1 << (ASORT_RADIX_BITS)) - 1)
/* Just the splitting part of QuickSort */
-static void Q(quicksplit)(void *array_ptr, uns num_elts, uns *leftp, uns *rightp)
+static void Q(quicksplit)(void *array_ptr, uns num_elts, int *leftp, int *rightp)
{
Q(key) *array = array_ptr;
int l, r, m;
#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,
return ctx.array;
}
-/* FIXME */
-#undef ASORT_PREFIX
+#undef ASORT_HASH
#undef ASORT_KEY_TYPE
+#undef ASORT_LONG_HASH
#undef ASORT_LT
-#undef ASORT_SWAP
-#undef ASORT_THRESHOLD
#undef ASORT_PAGE_ALIGNED
-#undef ASORT_HASH
+#undef ASORT_PREFIX
#undef ASORT_RADIX_BITS
#undef ASORT_RADIX_MASK
-#undef ASORT_LONG_HASH
+#undef ASORT_SWAP
+#undef ASORT_THRESHOLD
#undef Q