diff options
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | source/kit/lower_bound.h | 52 |
2 files changed, 27 insertions, 26 deletions
@@ -1,5 +1,6 @@ # kit - Unit-testing - Async function +- Lower bound - Dynamic array - Input buffer diff --git a/source/kit/lower_bound.h b/source/kit/lower_bound.h index 5b04557..fee1648 100644 --- a/source/kit/lower_bound.h +++ b/source/kit/lower_bound.h @@ -5,34 +5,34 @@ extern "C" { #endif -#define KIT_LOWER_BOUND(return_val, array, value, op) \ - { \ - ptrdiff_t position_ = 0; \ - ptrdiff_t count_ = (array).size; \ - while (count_ > 0) { \ - ptrdiff_t delta_ = count_ / 2; \ - if (op((array).values[position_ + delta_], (value))) { \ - position_ += delta_ + 1; \ - count_ -= delta_ + 1; \ - } else \ - count_ = delta_; \ - } \ - (return_val) = position_; \ +#define KIT_LOWER_BOUND(return_val, array, value, op) \ + { \ + ptrdiff_t position_ = 0; \ + ptrdiff_t count_ = (array).size; \ + while (count_ > 0) { \ + ptrdiff_t delta_ = count_ / 2; \ + if ((op) ((array).values[position_ + delta_], (value))) { \ + position_ += delta_ + 1; \ + count_ -= delta_ + 1; \ + } else \ + count_ = delta_; \ + } \ + (return_val) = position_; \ } -#define KIT_LOWER_BOUND_REF(return_val, array, value, op) \ - { \ - ptrdiff_t position_ = 0; \ - ptrdiff_t count_ = (array).size; \ - while (count_ > 0) { \ - ptrdiff_t delta_ = count_ / 2; \ - if (op((array).values + position_ + delta_, &(value))) { \ - position_ += delta_ + 1; \ - count_ -= delta_ + 1; \ - } else \ - count_ = delta_; \ - } \ - (return_val) = position_; \ +#define KIT_LOWER_BOUND_REF(return_val, array, value, op) \ + { \ + ptrdiff_t position_ = 0; \ + ptrdiff_t count_ = (array).size; \ + while (count_ > 0) { \ + ptrdiff_t delta_ = count_ / 2; \ + if ((op) ((array).values + position_ + delta_, &(value))) { \ + position_ += delta_ + 1; \ + count_ -= delta_ + 1; \ + } else \ + count_ = delta_; \ + } \ + (return_val) = position_; \ } #ifdef __cplusplus |