]> mj.ucw.cz Git - libucw.git/blobdiff - lib/sorter/govern.c
Added a magical constant estimating non-uniformity of hash functions.
[libucw.git] / lib / sorter / govern.c
index 388fac4a4dff8c9a359d5e74f92c95bde46f5b62..ddf919e2065d54e4f624dfed6f4a0bf3838f91ba 100644 (file)
@@ -171,26 +171,27 @@ sorter_twoway(struct sort_context *ctx, struct sort_bucket *b)
 static uns
 sorter_radix_bits(struct sort_context *ctx, struct sort_bucket *b)
 {
 static uns
 sorter_radix_bits(struct sort_context *ctx, struct sort_bucket *b)
 {
-  if (!b->hash_bits || !ctx->radix_split || (sorter_debug & SORT_DEBUG_NO_RADIX))
+  if (!b->hash_bits || !ctx->radix_split ||
+      (b->flags & SBF_CUSTOM_PRESORT) ||
+      (sorter_debug & SORT_DEBUG_NO_RADIX))
     return 0;
 
   u64 in = sbuck_size(b);
     return 0;
 
   u64 in = sbuck_size(b);
-  u64 mem = ctx->internal_estimate(ctx, b);
-  if (in < mem)
+  u64 mem = ctx->internal_estimate(ctx, b) * 0.8;      // FIXME: Magical factor for hash non-uniformity
+  if (in <= mem)
     return 0;
 
     return 0;
 
-  uns n;
-  for (n = sorter_min_radix_bits; n < sorter_max_radix_bits && n < b->hash_bits; n++)
-    if ((in >> n) < mem)
-      break;
+  uns n = sorter_min_radix_bits;
+  while (n < sorter_max_radix_bits && n < b->hash_bits && (in >> n) > mem)
+    n++;
   return n;
 }
 
 static void
   return n;
 }
 
 static void
-    sorter_radix(struct sort_context *ctx, struct sort_bucket *b, uns bits)
+sorter_radix(struct sort_context *ctx, struct sort_bucket *b, uns bits)
 {
   uns nbuck = 1 << bits;
 {
   uns nbuck = 1 << bits;
-  SORT_XTRACE(2, "Running radix sort on %s with %d bits of %d (expected size %s)",
+  SORT_XTRACE(2, "Running radix split on %s with hash %d bits of %d (expecting %s buckets)",
              F_BSIZE(b), bits, b->hash_bits, stk_fsize(sbuck_size(b) / nbuck));
   sorter_start_timer(ctx);
 
              F_BSIZE(b), bits, b->hash_bits, stk_fsize(sbuck_size(b) / nbuck));
   sorter_start_timer(ctx);