Skip to content

Commit 50edef3

Browse files
authored
MOD-13821 Fix compression with total_weight=1 (#39)
1 parent 5b89d70 commit 50edef3

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

‎src/tdigest.c‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,8 +608,17 @@ int td_compress(td_histogram_t *h) {
608608
const int overflow_res = _check_td_overflow((double)h->unmerged_weight, (double)total_weight);
609609
if (overflow_res != 0)
610610
return overflow_res;
611-
if (total_weight <= 1)
611+
if (total_weight <= 1) {
612+
// Only move data if there are unmerged nodes to move
613+
if (h->unmerged_nodes > 0) {
614+
h->merged_nodes = h->merged_nodes + h->unmerged_nodes;
615+
h->merged_weight = total_weight;
616+
h->unmerged_nodes = 0;
617+
h->unmerged_weight = 0;
618+
h->total_compressions++;
619+
}
612620
return 0;
621+
}
613622
const double denom = 2 * MM_PI * total_weight * log(total_weight);
614623
if (_check_overflow(denom) != 0)
615624
return EDOM;

0 commit comments

Comments
 (0)