]> mj.ucw.cz Git - libucw.git/blobdiff - lib/sorter/sorter.h
Completely rewritten buffer management of the sorter.
[libucw.git] / lib / sorter / sorter.h
index 98dd8f776e3aa0bacc0e4423217c26a440ec328a..c2905345e910feaa6d26da100c7894d43b21bc7e 100644 (file)
  *  void PREFIX_write_merged(struct fastbuf *f, SORT_KEY **keys, void **data, uns n, void *buf)
  *                     takes n records in memory with keys which compare equal and writes
  *                     a single record to the given fastbuf. `buf' points to a buffer which
  *  void PREFIX_write_merged(struct fastbuf *f, SORT_KEY **keys, void **data, uns n, void *buf)
  *                     takes n records in memory with keys which compare equal and writes
  *                     a single record to the given fastbuf. `buf' points to a buffer which
- *                     is guaranteed to hold all given records.
+ *                     is guaranteed to hold the sum of workspace requirements (see below)
+ *                     over all given records.
  *  void PREFIX_copy_merged(SORT_KEY **keys, struct fastbuf **data, uns n, struct fastbuf *dest)
  *                     takes n records with keys in memory and data in fastbufs and writes
  *                     a single record.
  *  void PREFIX_copy_merged(SORT_KEY **keys, struct fastbuf **data, uns n, struct fastbuf *dest)
  *                     takes n records with keys in memory and data in fastbufs and writes
  *                     a single record.
+ *  SORT_UNIFY_WORKSPACE(key)  gets a key and returns the amount of workspace required when merging
+ *                     the given record. Defaults to 0.
  *
  *  Input (choose one of these):
  *
  *
  *  Input (choose one of these):
  *
@@ -75,6 +78,8 @@
  *                     to get successive batches of pre-sorted data.
  *                     The function is passed a page-aligned presorting buffer.
  *                     It returns 1 on success or 0 on EOF.
  *                     to get successive batches of pre-sorted data.
  *                     The function is passed a page-aligned presorting buffer.
  *                     It returns 1 on success or 0 on EOF.
+ *  SORT_DELETE_INPUT  A C expression, if true, then the input files are deleted
+ *                     as soon as possible.
  *
  *  Output (chose one of these):
  *
  *
  *  Output (chose one of these):
  *
@@ -88,7 +93,7 @@
  *
  *  The function generated:
  *
  *
  *  The function generated:
  *
- *  <outfb> PREFIX_SORT(<in>, <out> [,<range>]), where:
+ *  <outfb> PREFIX_sort(<in>, <out> [,<range>]), where:
  *                     <in> = input file name/fastbuf or NULL
  *                     <out> = output file name/fastbuf or NULL
  *                     <range> = maximum integer value for the SORT_INT mode
  *                     <in> = input file name/fastbuf or NULL
  *                     <out> = output file name/fastbuf or NULL
  *                     <range> = maximum integer value for the SORT_INT mode
@@ -172,7 +177,12 @@ static inline void P(copy_data)(P(key) *key, struct fastbuf *in, struct fastbuf
 #endif
 }
 
 #endif
 }
 
+#if defined(SORT_VAR_KEY) || defined(SORT_VAR_DATA) || defined(SORT_UNIFY_WORKSPACE)
 #include "lib/sorter/s-internal.h"
 #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)
 #include "lib/sorter/s-twoway.h"
 
 #if defined(SORT_HASH_BITS) || defined(SORT_INT)
@@ -214,6 +224,10 @@ static struct fastbuf *P(sort)(
 #else
 #error No input given.
 #endif
 #else
 #error No input given.
 #endif
+#ifdef SORT_DELETE_INPUT
+  if (SORT_DELETE_INPUT)
+    bconfig(ctx.in_fb, BCONFIG_IS_TEMP_FILE, 1);
+#endif
 
 #ifdef SORT_OUTPUT_FB
   ASSERT(!out);
 
 #ifdef SORT_OUTPUT_FB
   ASSERT(!out);
@@ -236,6 +250,7 @@ static struct fastbuf *P(sort)(
 #endif
 
   ctx.internal_sort = P(internal);
 #endif
 
   ctx.internal_sort = P(internal);
+  ctx.internal_estimate = P(internal_estimate);
   ctx.twoway_merge = P(twoway_merge);
 
   sorter_run(&ctx);
   ctx.twoway_merge = P(twoway_merge);
 
   sorter_run(&ctx);
@@ -260,6 +275,7 @@ static struct fastbuf *P(sort)(
 #undef SORT_INT
 #undef SORT_HASH_BITS
 #undef SORT_UNIFY
 #undef SORT_INT
 #undef SORT_HASH_BITS
 #undef SORT_UNIFY
+#undef SORT_UNIFY_WORKSPACE
 #undef SORT_INPUT_FILE
 #undef SORT_INPUT_FB
 #undef SORT_INPUT_PRESORT
 #undef SORT_INPUT_FILE
 #undef SORT_INPUT_FB
 #undef SORT_INPUT_PRESORT
@@ -268,6 +284,7 @@ static struct fastbuf *P(sort)(
 #undef SORT_OUTPUT_THIS_FB
 #undef SORT_UNIQUE
 #undef SORT_ASSERT_UNIQUE
 #undef SORT_OUTPUT_THIS_FB
 #undef SORT_UNIQUE
 #undef SORT_ASSERT_UNIQUE
+#undef SORT_DELETE_INPUT
 #undef SWAP
 #undef LESS
 #undef P
 #undef SWAP
 #undef LESS
 #undef P