|
cctools
|
Keep counts of doubles that fall in some given bucket size. More...
#include "int_sizes.h"Go to the source code of this file.
Functions | |
| struct histogram * | histogram_create (double bucket_size) |
| Create a new histogram. More... | |
| void | histogram_clear (struct histogram *h) |
| Remove all entries from a histogram. More... | |
| void | histogram_delete (struct histogram *h) |
| Delete a histogram. More... | |
| int | histogram_size (struct histogram *h) |
| Count the number of active buckets. More... | |
| double * | histogram_buckets (struct histogram *h) |
| Returns an ordered array with the start values of the active buckets. More... | |
| double | histogram_bucket_size (struct histogram *h) |
| Returns the bucket size. More... | |
| int | histogram_insert (struct histogram *h, double value) |
| Add value to histogram. More... | |
| int | histogram_count (struct histogram *h, double value) |
| Look up the count for the bucket of the given value. More... | |
| void | histogram_set_bucket (struct histogram *h, double value, int count) |
| Manually set the count for a bucket. More... | |
| void | histogram_attach_data (struct histogram *h, double value, void *data) |
| Attach custom data to bucket. More... | |
| void * | histogram_get_data (struct histogram *h, double value) |
| Retrieved custom data attached to the bucket. More... | |
| int | histogram_total_count (struct histogram *h) |
| Return the total number of samples in the histogram. More... | |
| double | histogram_max_value (struct histogram *h) |
| Return the maximum value inserted in the histogram. More... | |
| double | histogram_min_value (struct histogram *h) |
| Return the minimum value inserted in the histogram. More... | |
| double | histogram_round_up (struct histogram *h, double test_value) |
| Return the largest value of the bucket that test_value would faill in. More... | |
| double | histogram_mode (struct histogram *h) |
| Return the mode of the histogram. More... | |
Keep counts of doubles that fall in some given bucket size.
struct histogram *h;
double bucket_size = .5;
h = histogram_create(bucket_size);
// same bucket
histogram_insert(h, 3.0);
histogram_insert(h, 3.1415);
// same bucket
histogram_insert(h, 21.999);
// same bucket
histogram_insert(h, 22.0);
histogram_insert(h, 22.2);
histogram_insert(h, 22.499);
// same bucket
histogram_insert(h, 22.5);
// same bucket
histogram_insert(h, -21.999);
// same bucket
histogram_insert(h, -22.0);
histogram_insert(h, -22.2);
histogram_insert(h, -22.499);
// same bucket
histogram_insert(h, -22.5);
double *buckets = histogram_buckets(h);
double b = histogram_bucket_size(h);
int i;
for(i = 0; i < histogram_size(h); i++) {
double start = buckets[i];
fprintf(stdout, "[%lf, $lf) has %d elements.\n", start, start + b, histogram_count(h, start));
}
free(buckets);
histogram_delete(h);
| struct histogram* histogram_create | ( | double | bucket_size | ) |
Create a new histogram.
| bucket_size | Numbers are grouped according to [n*bucket_size, (n+1)*bucket_size), n in Z. |
| void histogram_clear | ( | struct histogram * | h | ) |
Remove all entries from a histogram.
| h | The histogram to clear. |
| void histogram_delete | ( | struct histogram * | h | ) |
Delete a histogram.
| h | The histogram to delete. |
| int histogram_size | ( | struct histogram * | h | ) |
Count the number of active buckets.
| h | A pointer to a histogram. |
| double* histogram_buckets | ( | struct histogram * | h | ) |
Returns an ordered array with the start values of the active buckets.
| double histogram_bucket_size | ( | struct histogram * | h | ) |
Returns the bucket size.
| int histogram_insert | ( | struct histogram * | h, |
| double | value | ||
| ) |
Add value to histogram.
| h | A pointer to a histogram. |
| value | A number to add to the histogram. |
| int histogram_count | ( | struct histogram * | h, |
| double | value | ||
| ) |
Look up the count for the bucket of the given value.
| h | A pointer to a histogram. |
| value | A number that would fall inside the desired bucket. |
| void histogram_set_bucket | ( | struct histogram * | h, |
| double | value, | ||
| int | count | ||
| ) |
Manually set the count for a bucket.
| h | A pointer to a histogram. |
| value | A number that would fall inside the desired bucket. |
| count | The desired count. |
| void histogram_attach_data | ( | struct histogram * | h, |
| double | value, | ||
| void * | data | ||
| ) |
Attach custom data to bucket.
| h | A pointer to a histogram. |
| value | A number that would fall inside the desired bucket. |
| data | A pointer to external data. |
| void* histogram_get_data | ( | struct histogram * | h, |
| double | value | ||
| ) |
Retrieved custom data attached to the bucket.
| h | A pointer to a histogram. |
| value | A number that would fall inside the desired bucket. |
| int histogram_total_count | ( | struct histogram * | h | ) |
Return the total number of samples in the histogram.
| h | A pointer to a histogram. |
| double histogram_max_value | ( | struct histogram * | h | ) |
Return the maximum value inserted in the histogram.
| h | A pointer to a histogram. |
| double histogram_min_value | ( | struct histogram * | h | ) |
Return the minimum value inserted in the histogram.
| h | A pointer to a histogram. |
| double histogram_round_up | ( | struct histogram * | h, |
| double | test_value | ||
| ) |
Return the largest value of the bucket that test_value would faill in.
| h | A pointer to a histogram. |
| test_value | value to round up |
| double histogram_mode | ( | struct histogram * | h | ) |
Return the mode of the histogram.
| h | A pointer to a histogram. |