]> mj.ucw.cz Git - libucw.git/blobdiff - lib/sorter/sorter.h
A subset of tests can be requested now. Also, the radix sort width
[libucw.git] / lib / sorter / sorter.h
index 83d3e7dcacf32203528e634190914dd69780354b..c8924840135d2f0d0337d093d8c1160bea41f21a 100644 (file)
@@ -131,6 +131,7 @@ typedef SORT_KEY P(key);
 #ifdef SORT_INT64
 typedef u64 P(hash_t);
 #define SORT_INT SORT_INT64
+#define SORT_LONG_HASH
 #else
 typedef uns P(hash_t);
 #endif
@@ -193,6 +194,11 @@ static inline void P(copy_merged)(P(key) **keys, struct fastbuf **data UNUSED, u
 }
 #endif
 
+#if defined(SORT_HASH_BITS) || defined(SORT_INT)
+#define SORT_INTERNAL_RADIX
+#include "lib/sorter/s-radix.h"
+#endif
+
 #if defined(SORT_VAR_KEY) || defined(SORT_VAR_DATA) || defined(SORT_UNIFY_WORKSPACE)
 #include "lib/sorter/s-internal.h"
 #else
@@ -200,10 +206,7 @@ static inline void P(copy_merged)(P(key) **keys, struct fastbuf **data UNUSED, u
 #endif
 
 #include "lib/sorter/s-twoway.h"
-
-#if defined(SORT_HASH_BITS) || defined(SORT_INT)
-#include "lib/sorter/s-radix.h"
-#endif
+#include "lib/sorter/s-multiway.h"
 
 static struct fastbuf *P(sort)(
 #ifdef SORT_INPUT_FILE
@@ -225,7 +228,7 @@ static struct fastbuf *P(sort)(
   bzero(&ctx, sizeof(ctx));
 
 #ifdef SORT_INPUT_FILE
-  ctx.in_fb = bopen(in, O_RDONLY, sorter_stream_bufsize);
+  ctx.in_fb = bopen_file(in, O_RDONLY, &sorter_fb_params);
   ctx.in_size = bfilesize(ctx.in_fb);
 #elif defined(SORT_INPUT_FB)
   ctx.in_fb = in;
@@ -268,41 +271,41 @@ static struct fastbuf *P(sort)(
   ctx.internal_sort = P(internal);
   ctx.internal_estimate = P(internal_estimate);
   ctx.twoway_merge = P(twoway_merge);
+  ctx.multiway_merge = P(multiway_merge);
 
   sorter_run(&ctx);
 
 #ifdef SORT_OUTPUT_FILE
-  if (rename(ctx.out_fb->name, out) < 0)
-    die("Cannot rename %s to %s: %m", ctx.out_fb->name, out);
-  bconfig(ctx.out_fb, BCONFIG_IS_TEMP_FILE, 0);
-  bclose(ctx.out_fb);
+  bfix_tmp_file(ctx.out_fb, out);
   ctx.out_fb = NULL;
 #endif
   return ctx.out_fb;
 }
 
-#undef SORT_PREFIX
-#undef SORT_KEY
-#undef SORT_KEY_REGULAR
-#undef SORT_KEY_SIZE
+#undef SORT_ASSERT_UNIQUE
 #undef SORT_DATA_SIZE
-#undef SORT_VAR_KEY
-#undef SORT_VAR_DATA
-#undef SORT_INT
-#undef SORT_INT64
+#undef SORT_DELETE_INPUT
 #undef SORT_HASH_BITS
-#undef SORT_UNIFY
-#undef SORT_UNIFY_WORKSPACE
-#undef SORT_INPUT_FILE
 #undef SORT_INPUT_FB
+#undef SORT_INPUT_FILE
+#undef SORT_INPUT_PIPE
 #undef SORT_INPUT_PRESORT
-#undef SORT_OUTPUT_FILE
+#undef SORT_INT
+#undef SORT_INT64
+#undef SORT_INTERNAL_RADIX
+#undef SORT_KEY
+#undef SORT_KEY_REGULAR
+#undef SORT_KEY_SIZE
+#undef SORT_LONG_HASH
 #undef SORT_OUTPUT_FB
+#undef SORT_OUTPUT_FILE
 #undef SORT_OUTPUT_THIS_FB
+#undef SORT_PREFIX
+#undef SORT_UNIFY
+#undef SORT_UNIFY_WORKSPACE
 #undef SORT_UNIQUE
-#undef SORT_ASSERT_UNIQUE
-#undef SORT_DELETE_INPUT
+#undef SORT_VAR_DATA
+#undef SORT_VAR_KEY
 #undef SWAP
 #undef LESS
 #undef P
-/* FIXME: Check that we undef everything we should. */