From: Martin Mares Date: Sat, 10 Feb 2007 13:14:50 +0000 (+0100) Subject: Added s-fixint module (internal sorter for small fixed-size records). X-Git-Tag: holmes-import~506^2~13^2~151 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=f0459952ab7a84b2a2e16ee38456087b0986a228;p=libucw.git Added s-fixint module (internal sorter for small fixed-size records). --- diff --git a/lib/sorter/s-fixint.h b/lib/sorter/s-fixint.h new file mode 100644 index 00000000..a36be558 --- /dev/null +++ b/lib/sorter/s-fixint.h @@ -0,0 +1,59 @@ +/* + * UCW Library -- Universal Sorter: Fixed-Size Internal Sorting Module + * + * (c) 2007 Martin Mares + * + * This software may be freely distributed and used according to the terms + * of the GNU Lesser General Public License. + */ + +#define ASORT_PREFIX(x) SORT_PREFIX(array_##x) +#define ASORT_KEY_TYPE P(key) +#define ASORT_ELT(i) ary[i] +#define ASORT_LT(x,y) (P(compare)(&(x), &(y)) < 0) +#define ASORT_EXTRA_ARGS , P(key) *ary +#include "lib/arraysort.h" + +static int P(internal)(struct sort_context *ctx, struct sort_bucket *bin, struct sort_bucket *bout, struct sort_bucket *bout_only) +{ + sorter_alloc_buf(ctx); + struct fastbuf *in = sbuck_read(bin); + P(key) *buf = ctx->big_buf; + size_t bufsize = ctx->big_buf_half_size; /* FIXME: In some cases, we can use the whole buffer */ +#ifdef CPU_64BIT_POINTERS + bufsize = MIN((u64)bufsize, (u64)~0U * sizeof(P(key))); // The number of records must fit in uns +#endif + uns maxkeys = bufsize / sizeof(P(key)); + + SORT_XTRACE(3, "s-fixint: Reading (maxkeys=%u)", maxkeys); + uns n = 0; + while (n < maxkeys && P(read_key)(in, &buf[n])) + n++; + + SORT_XTRACE(3, "s-fixint: Sorting %u items", n); + P(array_sort)(n, buf); + + SORT_XTRACE(3, "s-fixint: Writing"); + struct fastbuf *out = sbuck_write((n < maxkeys) ? bout_only : bout); + bout->runs++; + uns merged UNUSED = 0; + for (uns i=0; imore_keys; diff --git a/lib/sorter/sorter.h b/lib/sorter/sorter.h index 98dd8f77..39bdcb97 100644 --- a/lib/sorter/sorter.h +++ b/lib/sorter/sorter.h @@ -172,7 +172,12 @@ static inline void P(copy_data)(P(key) *key, struct fastbuf *in, struct fastbuf #endif } +#if defined(SORT_VAR_KEY) || defined(SORT_VAR_DATA) || defined(SORT_UNIFY) #include "lib/sorter/s-internal.h" +#else +#include "lib/sorter/s-fixint.h" +#endif + #include "lib/sorter/s-twoway.h" #if defined(SORT_HASH_BITS) || defined(SORT_INT)