|
PebbleOS
|
Basic statistics over arrays of int32_t.
More...
Typedefs | |
| typedef bool(* | pbl_stats_filter_t) (int index, int32_t value, void *context) |
| Filter of the values included in pbl_stats_calculate(). | |
Enumerations | |
| enum | pbl_stats_op { PBL_STATS_OP_SUM = (1 << 0) , PBL_STATS_OP_AVERAGE = (1 << 1) , PBL_STATS_OP_MIN = (1 << 2) , PBL_STATS_OP_MAX = (1 << 3) , PBL_STATS_OP_COUNT = (1 << 4) , PBL_STATS_OP_CONSECUTIVE = (1 << 5) , PBL_STATS_OP_CONSECUTIVE_FIRST = (1 << 6) , PBL_STATS_OP_MEDIAN = (1 << 7) } |
| Operations of pbl_stats_calculate(), combined as a bit field. More... | |
Functions | |
| void | pbl_stats_calculate (enum pbl_stats_op op, const int32_t *data, size_t num_data, pbl_stats_filter_t filter, void *context, int32_t *basic_out) |
| Calculate basic statistics over an array. | |
| int32_t | pbl_stats_weighted_median (const int32_t *vals, const int32_t *weights_x100, size_t num_data) |
| Calculate the weighted median of an array. | |
Basic statistics over arrays of int32_t.
| typedef bool(* pbl_stats_filter_t) (int index, int32_t value, void *context) |
Filter of the values included in pbl_stats_calculate().
| index | Index of the value in the data array. |
| value | Value. |
| context | Filter data. |
| enum pbl_stats_op |
Operations of pbl_stats_calculate(), combined as a bit field.
With a filter, every operation only considers the values it accepts.
| void pbl_stats_calculate | ( | enum pbl_stats_op | op, |
| const int32_t * | data, | ||
| size_t | num_data, | ||
| pbl_stats_filter_t | filter, | ||
| void * | context, | ||
| int32_t * | basic_out | ||
| ) |
Calculate basic statistics over an array.
Results are written to basic_out in the order of enum pbl_stats_op, without gaps: for PBL_STATS_OP_MAX | PBL_STATS_OP_SUM, basic_out[0] is the sum and basic_out[1] the maximum.
| op | Operations, a combination of enum pbl_stats_op. | |
| data | Values. Nothing is written if NULL. | |
| num_data | Number of values. | |
| filter | Filter, or NULL to include every value. | |
| context | Filter data. | |
| [out] | basic_out | One result per operation in op. |
| int32_t pbl_stats_weighted_median | ( | const int32_t * | vals, |
| const int32_t * | weights_x100, | ||
| size_t | num_data | ||
| ) |
Calculate the weighted median of an array.
The weighted median is the value x[k] such that the total weight of the values below it and the total weight of the values above it are each at most half the total weight. When two values qualify, their mean is returned. Uses integer division throughout and allocates a temporary copy with calloc().
| vals | Values. |
| weights_x100 | Positive weights, scaled by 100. |
| num_data | Number of values. |