]> mj.ucw.cz Git - libucw.git/blobdiff - lib/sorter/s-internal.h
Fix bucket estimator.
[libucw.git] / lib / sorter / s-internal.h
index 665234fea2ba9168f3f04af9a568c1b837e2dbbf..05fc7e982475495e2ba83f53a6b11eaa1ecb86ba 100644 (file)
@@ -91,7 +91,7 @@ static int P(internal)(struct sort_context *ctx, struct sort_bucket *bin, struct
   last_item = item;
 
   uns count = last_item - item_array;
-  SORT_XTRACE(3, "s-internal: Sorting %d items", count);
+  SORT_XTRACE(3, "s-internal: Sorting %u items", count);
   P(array_sort)(count, item_array);
 
   SORT_XTRACE(3, "s-internal: Writing");
@@ -132,8 +132,21 @@ static int P(internal)(struct sort_context *ctx, struct sort_bucket *bin, struct
 #endif
     }
 #ifdef SORT_UNIFY
-  SORT_XTRACE(3, "Merging reduced %d records", merged);
+  SORT_XTRACE(3, "Merging reduced %u records", merged);
 #endif
 
   return ctx->more_keys;
 }
+
+static u64
+P(internal_estimate)(struct sort_context *ctx, struct sort_bucket *b UNUSED)
+{
+  uns avg;
+#ifdef SORT_VAR_KEY
+  avg = ALIGN_TO(sizeof(P(key))/4, CPU_STRUCT_ALIGN);  // Wild guess...
+#else
+  avg = ALIGN_TO(sizeof(P(key)), CPU_STRUCT_ALIGN);
+#endif
+  // We ignore the data part of records, it probably won't make the estimate much worse
+  return (ctx->big_buf_half_size / (avg + sizeof(P(internal_item_t))) * avg);
+}