From 4429ed09b548518dbffce7ec77ddf5a8b09484b2 Mon Sep 17 00:00:00 2001 From: Mitya Selivanov <0x7fffff@guattari.ru> Date: Sun, 7 Aug 2022 08:37:53 +0400 Subject: Refactor --- README.md | 1 + source/kit/lower_bound.h | 52 ++++++++++++++++++++++++------------------------ 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index e19d0d6..ad780ac 100644 --- a/README.md +++ b/README.md @@ -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 -- cgit v1.2.3