add a value to the t-digest, trigger a compaction if full */
| 563 | |
| 564 | /* add a value to the t-digest, trigger a compaction if full */ |
| 565 | static void |
| 566 | tdigest_add(tdigest_aggstate_t *state, double v) |
| 567 | { |
| 568 | int compression = state->compression; |
| 569 | int ncentroids = state->ncentroids; |
| 570 | |
| 571 | /* make sure we have space for the value */ |
| 572 | Assert(state->ncentroids < BUFFER_SIZE(compression)); |
| 573 | |
| 574 | /* for a single point, the value is both sum and mean */ |
| 575 | state->centroids[ncentroids].count = 1; |
| 576 | state->centroids[ncentroids].mean = v; |
| 577 | state->ncentroids++; |
| 578 | state->count++; |
| 579 | |
| 580 | Assert(state->ncentroids <= BUFFER_SIZE(compression)); |
| 581 | |
| 582 | /* if the buffer got full, trigger compaction here so that next |
| 583 | * insert has free space */ |
| 584 | if (state->ncentroids == BUFFER_SIZE(compression)) |
| 585 | { |
| 586 | tdigest_compact(state); |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | |
| 591 | /* |
no test coverage detected