diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-04-01 16:25:03 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-04-01 16:25:03 +0200 |
commit | 007e935009a685d3c5ee7d3fd9b77448f9eaae04 (patch) | |
tree | 4ced7b6c0b379ef6f58268ae51aeff8556d72f0b | |
parent | 8c2f9268ab976015edcff16e26a13398bba8396c (diff) |
Fix binary search macro
-rw-r--r-- | include/__bsearch.h | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/include/__bsearch.h b/include/__bsearch.h index e6b181b..d0dbf81 100644 --- a/include/__bsearch.h +++ b/include/__bsearch.h @@ -6,18 +6,17 @@ static TYPE mlib_lookup(rune ch) \ { \ ptrdiff_t i, lo, hi; \ - if (ch >= lengthof(TABLE)) \ - return DEFAULT; \ lo = 0; \ hi = lengthof(TABLE) - 1; \ i = (lo + hi) / 2; \ do { \ if (ch < TABLE[i].lo) \ hi = i - 1; \ - else if (ch >= TABLE[i].hi) \ + else if (ch > TABLE[i].hi) \ lo = i + 1; \ else \ return TABLE[i].val; \ + i = (lo + hi) / 2; \ } while (lo <= hi); \ return DEFAULT; \ } |