Skip to content

Commit

Permalink
optimize roaring_bitmap_statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
AviAvni committed May 5, 2024
1 parent 5b28660 commit fc9ecf7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 25 deletions.
3 changes: 1 addition & 2 deletions include/roaring/roaring_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ typedef struct roaring_statistics_s {
max_value; /* the maximal value, undefined if cardinality is zero */
uint32_t
min_value; /* the minimal value, undefined if cardinality is zero */
uint64_t sum_value; /* the sum of all values (could be used to compute
average) */
uint64_t sum_value; /* deprecated always zero */

uint64_t cardinality; /* total number of values stored in the bitmap */

Expand Down
26 changes: 3 additions & 23 deletions src/roaring.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,20 +371,6 @@ void roaring_bitmap_printf_describe(const roaring_bitmap_t *r) {
printf("}");
}

typedef struct min_max_sum_s {
uint32_t min;
uint32_t max;
uint64_t sum;
} min_max_sum_t;

static bool min_max_sum_fnc(uint32_t value, void *param) {
min_max_sum_t *mms = (min_max_sum_t *)param;
if (value > mms->max) mms->max = value;
if (value < mms->min) mms->min = value;
mms->sum += value;
return true; // we always process all data points
}

/**
* (For advanced users.)
* Collect statistics about the bitmap
Expand All @@ -395,15 +381,8 @@ void roaring_bitmap_statistics(const roaring_bitmap_t *r,

memset(stat, 0, sizeof(*stat));
stat->n_containers = ra->size;
stat->cardinality = roaring_bitmap_get_cardinality(r);
min_max_sum_t mms;
mms.min = UINT32_C(0xFFFFFFFF);
mms.max = UINT32_C(0);
mms.sum = 0;
roaring_iterate(r, &min_max_sum_fnc, &mms);
stat->min_value = mms.min;
stat->max_value = mms.max;
stat->sum_value = mms.sum;
stat->min_value = roaring_bitmap_minimum(r);
stat->max_value = roaring_bitmap_maximum(r);

for (int i = 0; i < ra->size; ++i) {
uint8_t truetype =
Expand All @@ -412,6 +391,7 @@ void roaring_bitmap_statistics(const roaring_bitmap_t *r,
container_get_cardinality(ra->containers[i], ra->typecodes[i]);
uint32_t sbytes =
container_size_in_bytes(ra->containers[i], ra->typecodes[i]);
stat->cardinality += card;
switch (truetype) {
case BITSET_CONTAINER_TYPE:
stat->n_bitset_containers++;
Expand Down

0 comments on commit fc9ecf7

Please sign in to comment.