- sum += cnt_to_dbl(&entry->cnt);
- }
- count = max - min + 1;
- }
- else {
- sum = 0.0;
- count = 0;
- for (entry = pset_first(tbl->hash_map); entry; entry = pset_next(tbl->hash_map)) {
- sum += cnt_to_dbl(&entry->cnt);
- ++count;
- }
- }
+/*
+ * calculates the mean value of a distribution
+ */
+double stat_calc_mean_distrib_tbl(distrib_tbl_t *tbl) {
+ distrib_entry_t *entry;
+ unsigned count;
+ double sum;
+
+ if (tbl->int_dist) {
+ /* integer distribution, need min, max */
+ int min, max;
+
+ entry = pset_first(tbl->hash_map);
+
+ if (! entry)
+ return 0.0;
+
+ min =
+ max = PTR_TO_INT(entry->object);
+ sum = cnt_to_dbl(&entry->cnt);
+
+
+ for (entry = pset_next(tbl->hash_map); entry; entry = pset_next(tbl->hash_map)) {
+ int value = PTR_TO_INT(entry->object);
+
+ if (value < min)
+ min = value;
+ if (value > max)
+ max = value;
+
+ sum += cnt_to_dbl(&entry->cnt);
+ }
+ count = max - min + 1;
+ } else {
+ sum = 0.0;
+ count = 0;
+ foreach_pset(tbl->hash_map, entry) {
+ sum += cnt_to_dbl(&entry->cnt);
+ ++count;
+ }
+ }
+
+ return count ? sum / (double)count : 0.0;
+}