]> mj.ucw.cz Git - libucw.git/blobdiff - lib/sorter/govern.c
Changed the interface of the array sorter: the buffer and hash_bits parameters
[libucw.git] / lib / sorter / govern.c
index f761eb7df9e9ed23e104b655f5eaefd499d4a0b5..13fc7a61404f801d5125f081423960cb9de0bebc 100644 (file)
@@ -50,7 +50,7 @@ sorter_presort(struct sort_context *ctx, struct sort_bucket *in, struct sort_buc
     {
       struct fastbuf *f = sbuck_write(out);
       out->runs++;
     {
       struct fastbuf *f = sbuck_write(out);
       out->runs++;
-      return ctx->custom_presort(f, ctx->big_buf, ctx->big_buf_size);  // FIXME: out_only optimization?
+      return ctx->custom_presort(f, ctx->big_buf, ctx->big_buf_size);
     }
   return ctx->internal_sort(ctx, in, out, out_only);
 }
     }
   return ctx->internal_sort(ctx, in, out, out_only);
 }
@@ -226,7 +226,7 @@ sorter_multiway(struct sort_context *ctx, struct sort_bucket *b)
 
   if (part_cnt <= 1)
     {
 
   if (part_cnt <= 1)
     {
-      sh_off_t size = sbuck_ins_or_join(clist_head(&parts), list_pos, join, join_size);
+      sh_off_t size = sbuck_ins_or_join(clist_head(&parts), list_pos, (part_cnt ? NULL : join), join_size);
       SORT_XTRACE(trace_level, "Sorted in memory (%s, %dMB/s)", stk_fsize(size), sorter_speed(ctx, size));
       return;
     }
       SORT_XTRACE(trace_level, "Sorted in memory (%s, %dMB/s)", stk_fsize(size), sorter_speed(ctx, size));
       return;
     }
@@ -325,7 +325,7 @@ sorter_decide(struct sort_context *ctx, struct sort_bucket *b)
   // How many bits of bucket size we have to reduce before it fits in the RAM?
   // (this is insanely large if the input size is unknown, but it serves our purpose)
   u64 insize = sbuck_size(b);
   // How many bits of bucket size we have to reduce before it fits in the RAM?
   // (this is insanely large if the input size is unknown, but it serves our purpose)
   u64 insize = sbuck_size(b);
-  u64 mem = ctx->internal_estimate(ctx, b) * 0.8;      // FIXME: Magical factor for various non-uniformities
+  u64 mem = ctx->internal_estimate(ctx, b) * 0.8;      // Magical factor accounting for various non-uniformities
   uns bits = 0;
   while ((insize >> bits) > mem)
     bits++;
   uns bits = 0;
   while ((insize >> bits) > mem)
     bits++;
@@ -391,6 +391,7 @@ sorter_run(struct sort_context *ctx)
   ctx->pool = mp_new(4096);
   clist_init(&ctx->bucket_list);
   sorter_prepare_buf(ctx);
   ctx->pool = mp_new(4096);
   clist_init(&ctx->bucket_list);
   sorter_prepare_buf(ctx);
+  asort_start_threads(0);
 
   // Create bucket containing the source
   struct sort_bucket *bin = sbuck_new(ctx);
 
   // Create bucket containing the source
   struct sort_bucket *bin = sbuck_new(ctx);
@@ -419,6 +420,7 @@ sorter_run(struct sort_context *ctx)
   while (bout = clist_head(&ctx->bucket_list), b = clist_next(&ctx->bucket_list, &bout->n))
     sorter_decide(ctx, b);
 
   while (bout = clist_head(&ctx->bucket_list), b = clist_next(&ctx->bucket_list, &bout->n))
     sorter_decide(ctx, b);
 
+  asort_stop_threads();
   sorter_free_buf(ctx);
   sbuck_write(bout);           // Force empty bucket to a file
   SORT_XTRACE(2, "Final size: %s", F_BSIZE(bout));
   sorter_free_buf(ctx);
   sbuck_write(bout);           // Force empty bucket to a file
   SORT_XTRACE(2, "Final size: %s", F_BSIZE(bout));