#ifdef SORT_VAR_DATA
if (sizeof(key) + 1024 + SORT_DATA_SIZE(key) > ctx->big_buf_half_size)
{
- SORT_XTRACE("s-internal: Generating a giant run");
+ SORT_XTRACE(3, "s-internal: Generating a giant run");
struct fastbuf *out = sbuck_write(bout); /* FIXME: Using a non-direct buffer would be nice here */
P(copy_data)(&key, in, out);
bout->runs++;
bufsize = MIN((u64)bufsize, (u64)~0U * sizeof(P(internal_item_t))); // The number of records must fit in uns
#endif
- SORT_XTRACE("s-internal: Reading (bufsize=%zd)", bufsize);
+ SORT_XTRACE(3, "s-internal: Reading (bufsize=%zd)", bufsize);
P(internal_item_t) *item_array = ctx->big_buf, *item = item_array, *last_item;
byte *end = (byte *) ctx->big_buf + bufsize;
do
last_item = item;
uns count = last_item - item_array;
- SORT_XTRACE("s-internal: Sorting %d items", count);
+ SORT_XTRACE(3, "s-internal: Sorting %u items", count);
P(array_sort)(count, item_array);
- SORT_XTRACE("s-internal: Writing");
+ SORT_XTRACE(3, "s-internal: Writing");
if (!ctx->more_keys)
bout = bout_only;
struct fastbuf *out = sbuck_write(bout);
#endif
}
#ifdef SORT_UNIFY
- SORT_XTRACE("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);
+}