10 int histogram_init(struct histogram *h,
15 h->allocated = max_value/resolution + 1;
16 h->resolution = resolution;
17 mem = h->allocated*sizeof(*h->data);
18 h->data = malloc(mem);
20 memset(h->data, 0, mem);
26 void histogram_add(struct histogram *h, int value)
28 if (value < 0) value = 0;
29 unsigned index = value / h->resolution;
30 if (index >= h->allocated)
31 index = h->allocated - 1;
35 void histogram_fprint(struct histogram *h, FILE *f)
37 unsigned long long sum = 0, cum;
43 for (i = 0; i < h->allocated; i++)
46 for (i = 0; i < h->allocated; i++) {
47 if (h->data[i] != 0) {
48 fprintf(f, "%g %lld\n", 1e-3*(i*h->resolution), cum);