X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fsorter%2Farray.h;h=ef1d0551536d8d4461c7d6ac6abafc9ee196d989;hb=f1b56d292bbe248bf29c078d27986cdfbb1b3d39;hp=73da6908df5af00f4182fb3c046f05b5ee6110cb;hpb=0ce1209ffd78ede3a5d353393e281cc6a7995cd3;p=libucw.git diff --git a/lib/sorter/array.h b/lib/sorter/array.h index 73da6908..ef1d0551 100644 --- a/lib/sorter/array.h +++ b/lib/sorter/array.h @@ -8,11 +8,14 @@ */ /* - * This is a generator of routines for sorting arrays, very similar to the one - * in lib/arraysort.h. + * This is a generator of routines for sorting huge arrays, similar to the one + * in lib/arraysort.h. It cannot handle discontiguous arrays, but it is able + * to employ radix-sorting if a monotone hash function is available and also + * use several threads in parallel on SMP systems (this assumes that all + * callbacks you provide are thread-safe). * - * FIXME: - * FIXME: Note on thread-safety + * It is usually called internally by the generic shorter machinery, but + * you are free to use it explicitly if you need. * * So much for advocacy, there are the parameters (those marked with [*] * are mandatory): @@ -22,13 +25,19 @@ * ASORT_KEY_TYPE [*] data type of a single array entry key * ASORT_LT(x,y) x < y for ASORT_TYPE (default: "x x> shift) & ASORT_RADIX_MASK ] ++; +} + +static void Q(radix_split)(void *src_ptr, void *dest_ptr, uns num_elts, uns *ptrs, uns shift) +{ + Q(key) *src = src_ptr, *dest = dest_ptr; + for (uns i=0; i> shift) & ASORT_RADIX_MASK ]++ ] = src[i]; +} + +#endif + static Q(key) *Q(sort)(Q(key) *array, uns num_elts, Q(key) *buffer, uns hash_bits) { - (void) buffer; - (void) hash_bits; - Q(raw_sort)(array, num_elts); - return array; + struct asort_context ctx = { + .array = array, + .buffer = buffer, + .num_elts = num_elts, + .hash_bits = hash_bits, + .elt_size = sizeof(Q(key)), + .quicksort = Q(quicksort), +#ifdef ASORT_HASH + .radix_count = Q(radix_count), + .radix_split = Q(radix_split), + .radix_bits = ASORT_RADIX_BITS, +#endif + }; + asort_run(&ctx); + return ctx.array; } /* FIXME */ @@ -177,4 +221,6 @@ static Q(key) *Q(sort)(Q(key) *array, uns num_elts, Q(key) *buffer, uns hash_bit #undef ASORT_THRESHOLD #undef ASORT_PAGE_ALIGNED #undef ASORT_HASH +#undef ASORT_RADIX_BITS +#undef ASORT_RADIX_MASK #undef Q