like BINARY_ARRAY_SEARCH_V, but if an exact result is not found, the 'next'
argument will point to the element after the place where the exact result
would have been. If an exact result is found, 'next' will be NULL. If the
- target is beyond the end of the list, both 'result' and 'next' will be NULL.
+ target is beyond the end of the list, both 'exact' and 'next' will be NULL.
Unlike other binsearch macros, where there are several elements that compare
- the same, the result will always point to the first one.
+ the same, the exact result will always point to the first one.
If you don't care to distinguish between the 'greater than' and 'equals'
- cases, you can use the same pointer for both 'result' and 'next'.
+ cases, you can use the same pointer for both 'exact' and 'next'.
As with all the binsearch macros, the comparison function is always called
with the search term first.
*/
#define BINARY_ARRAY_SEARCH_GTE(array, array_size, target, comparison_fn, \
- result, next) do { \
+ exact, next) do { \
int32_t _b, _e; \
- (result) = NULL; (next) = NULL; \
+ (exact) = NULL; (next) = NULL; \
if ((array_size) > 0) { \
for (_b = 0, _e = (array_size)-1; _b <= _e; ) { \
int32_t _i = (_b + _e) / 2; \
int _r = comparison_fn(target, array[_i]); \
if (_r == 0) { \
- (result) = &array[_i]; \
+ (exact) = &array[_i]; \
_e = _i - 1; \
} else if (_r < 0) { _e = _i - 1; \
} else { _b = _i + 1; } \
} \
- if ((result) == NULL &&_b < (array_size)) { \
+ if ((exact) == NULL &&_b < (array_size)) { \
(next) = &array[_b]; \
} } } while (0)