diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-04-05 14:09:53 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-04-05 14:09:53 +0200 |
commit | 0abf844cd9c22623e22f462c91f380f16524c7e8 (patch) | |
tree | 697f853c8c1425cb918694916c48ff36d8c8ea33 /include | |
parent | 51d84ec3e1c9c6084f03b5d3ae9326a0287cfca6 (diff) |
Add __MLIB_DEFINE_BSEARCH_CONTAINS()
Diffstat (limited to 'include')
-rw-r--r-- | include/__bsearch.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/include/__bsearch.h b/include/__bsearch.h index d0dbf81..36dc6f3 100644 --- a/include/__bsearch.h +++ b/include/__bsearch.h @@ -21,6 +21,25 @@ return DEFAULT; \ } +#define __MLIB_DEFINE_BSEARCH_CONTAINS(TABLE) \ + static bool mlib_lookup_contains(rune ch) \ + { \ + ptrdiff_t i, lo, hi; \ + 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) \ + lo = i + 1; \ + else \ + return true; \ + i = (lo + hi) / 2; \ + } while (lo <= hi); \ + return false; \ + } + // [[gnu::always_inline]] static TYPE // lookup(rune ch) // { |