aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/__bsearch.h19
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)
// {