value_index.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #pragma once
  2. #include <stdint.h>
  3. #include <stdbool.h>
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. /** Get the index of a uint32_t array element which is closest to the given value.
  8. *
  9. * Returned index corresponds to the first element found.
  10. * If no suitable elements were found, the function returns 0.
  11. *
  12. * @param value value to be searched.
  13. * @param values pointer to the array to perform the search in.
  14. * @param values_count array size.
  15. *
  16. * @return value's index.
  17. */
  18. uint8_t value_index_uint32(const uint32_t value, const uint32_t values[], uint8_t values_count);
  19. /** Get the index of a float array element which is closest to the given value.
  20. *
  21. * Returned index corresponds to the first element found.
  22. * If no suitable elements were found, the function returns 0.
  23. *
  24. * @param value value to be searched.
  25. * @param values pointer to the array to perform the search in.
  26. * @param values_count array size.
  27. *
  28. * @return value's index.
  29. */
  30. uint8_t value_index_float(const float value, const float values[], uint8_t values_count);
  31. /** Get the index of a bool array element which is equal to the given value.
  32. *
  33. * Returned index corresponds to the first element found.
  34. * If no suitable elements were found, the function returns 0.
  35. *
  36. * @param value value to be searched.
  37. * @param values pointer to the array to perform the search in.
  38. * @param values_count array size.
  39. *
  40. * @return value's index.
  41. */
  42. uint8_t value_index_bool(const bool value, const bool values[], uint8_t values_count);
  43. #ifdef __cplusplus
  44. }
  45. #endif