X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fsorter.h;h=b61d630d9454cb22466592562a8c40824011c0ef;hb=fc0462c2b6efe086c5cc1c454864caf28db3a814;hp=9611e08279fef9ef45599bc06e5ec5275f9ea843;hpb=a4986daf333a317d29c825045f8e9748e3f3b8e6;p=libucw.git diff --git a/lib/sorter.h b/lib/sorter.h index 9611e082..b61d630d 100644 --- a/lib/sorter.h +++ b/lib/sorter.h @@ -18,10 +18,14 @@ * SORT_KEY [*] data type capable of storing a single key * SORT_PREFIX(x) [*] add a name prefix (used on all global names * defined by the sorter) - * SORT_PRESORT include an in-core presorting pass. Beware, when in + * SORT_PRESORT include an in-core pre-sorting pass. Beware, when in * the pre-sorting mode, it's quite possible that the * comparison function will be called with both arguments * identical. + * SORT_PRESORT_ONLY a C expression which, if evaluated to non-zero, makes + * the sorter stop after the pre-sorting pass, resulting + * in a file which is not necessarily sorted, but which + * contains long runs. Implies SORT_PRESORT. * SORT_UNIFY merge items with identical keys * SORT_UNIQUE all items have distinct keys (checked in debug mode) * SORT_REGULAR all items are equally long and they don't contain @@ -120,6 +124,13 @@ extern uns sorter_pass_counter; #define SORT_ASSERT_UNIQUE #endif +#ifdef SORT_PRESORT_ONLY +#undef SORT_PRESORT +#define SORT_PRESORT +#else +#define SORT_PRESORT_ONLY 0 +#endif + #ifdef SORT_REGULAR static inline int @@ -152,10 +163,7 @@ static struct fastbuf * P(flush_out)(struct fastbuf *out) { if (out) - { - bflush(out); - bsetpos(out, 0); - } + brewind(out); return out; } @@ -388,7 +396,8 @@ P(presort)(struct fastbuf **fb1, struct fastbuf **fb2) leftover = NULL; while (cont) { - SWAP(out1, out2, tbuf); + if (!(SORT_PRESORT_ONLY)) + SWAP(out1, out2, tbuf); if (!out1) out1 = bopen_tmp(sorter_stream_bufsize); current = buffer; @@ -542,5 +551,7 @@ struct fastbuf *fb1, struct fastbuf *fb2 #undef SORT_INPUT_FBPAIR #undef SORT_OUTPUT_FILE #undef SORT_OUTPUT_FB +#undef SORT_PRESORT +#undef SORT_PRESORT_ONLY #endif /* !SORT_DECLARE_ONLY */