| 1 | /* The MIT License |
| 2 | |
| 3 | Copyright (c) 2016 Genome Research Ltd. |
| 4 | |
| 5 | Author: Petr Danecek <[email protected]> |
| 6 | |
| 7 | Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 | of this software and associated documentation files (the "Software"), to deal |
| 9 | in the Software without restriction, including without limitation the rights |
| 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 | copies of the Software, and to permit persons to whom the Software is |
| 12 | furnished to do so, subject to the following conditions: |
| 13 | |
| 14 | The above copyright notice and this permission notice shall be included in |
| 15 | all copies or substantial portions of the Software. |
| 16 | |
| 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 23 | THE SOFTWARE. |
| 24 | |
| 25 | */ |
| 26 | |
| 27 | /* |
| 28 | Simple binning of float values into predefined bins |
| 29 | */ |
| 30 | |
| 31 | #ifndef __BIN_H__ |
| 32 | #define __BIN_H__ |
| 33 | |
| 34 | #include <stdio.h> |
| 35 | |
| 36 | typedef struct _bin_t bin_t; |
| 37 | |
| 38 | /* |
| 39 | * bin_init() - init bins |
| 40 | * @list: list of half-open intervals [). If the list does not contain commas, |
| 41 | * it is interpreted as a file name. |
| 42 | * @min,max: extreme values. This is for user convenience so that well-known |
| 43 | * extremes can be left out from the list. Ignored if min=max |
| 44 | */ |
| 45 | bin_t *bin_init(const char *list, float min, float max); |
| 46 | void bin_destroy(bin_t *bin); |
| 47 | |
| 48 | /* |
| 49 | * bin_get_size() - number of boundaries, subtract 1 to get the number of bins |
| 50 | */ |
| 51 | int bin_get_size(bin_t *bin); |
| 52 | |
| 53 | /* |
| 54 | bin_get_idx() - find the bin index which corresponds to the value (binary search) |
| 55 | Returns the bin index 0 <= idx <= size-2 or -1,size-1 for out of range values. |
| 56 | */ |
| 57 | int bin_get_idx(bin_t *bin, float value); |
| 58 | |
| 59 | /* |
| 60 | bin_get_value() - get the i-th boundary value, i=0,..,size-1 |
| 61 | */ |
| 62 | float bin_get_value(bin_t *bin, int ith); |
| 63 | |
| 64 | #endif |
| 65 |