MCPcopy Create free account
hub / github.com/documentdb/documentdb / tdigest_add

Function tdigest_add

pg_documentdb/src/aggregation/bson_tdigest.c:565–588  ·  view source on GitHub ↗

add a value to the t-digest, trigger a compaction if full */

Source from the content-addressed store, hash-verified

563
564/* add a value to the t-digest, trigger a compaction if full */
565static void
566tdigest_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/*

Callers 2

tdigest_add_doubleFunction · 0.85
tdigest_add_double_arrayFunction · 0.85

Calls 1

tdigest_compactFunction · 0.85

Tested by

no test coverage detected