diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-04-06 13:06:21 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-04-06 13:06:21 +0200 |
commit | b5b63552ff48ceb440a8dac590628ffe4e5e5751 (patch) | |
tree | a769314ea1247a3260ac0a305c94fcaff40ac6b0 /include | |
parent | 03f69018340f0fae95556321a3d89dcb49910ebe (diff) |
Add uprop_get_nv()
Diffstat (limited to 'include')
-rw-r--r-- | include/__bsearch.h | 55 | ||||
-rw-r--r-- | include/unicode/prop.h | 1 |
2 files changed, 19 insertions, 37 deletions
diff --git a/include/__bsearch.h b/include/__bsearch.h index 36dc6f3..6abcff6 100644 --- a/include/__bsearch.h +++ b/include/__bsearch.h @@ -40,40 +40,21 @@ return false; \ } -// [[gnu::always_inline]] static TYPE -// lookup(rune ch) -// { -// ptrdiff_t i, lo, hi; -// -// #ifdef LATIN1_TABLE -// if (ch <= LATIN1_MAX) -// return LATIN1_TABLE[ch]; -// #endif -// if (ch >= lengthof(TABLE)) -// return DEFAULT; -// -// lo = 0; -// hi = lengthof(TABLE) - 1; -// -// #ifdef INITIAL_INDEX -// i = INITIAL_INDEX; -// #else -// i = (lo + hi) / 2; -// #endif -// -// do { -// if (ch < TABLE[i].LO) -// hi = i - 1; -// else if (ch > TABLE[i].HI) -// lo = i + 1; -// else -// #if HAS_VALUE -// return TABLE[i].val; -// #else -// return true; -// #endif -// i = (lo + hi) / 2; -// } while (lo <= hi); -// -// return DEFAULT; -// } +#define __MLIB_DEFINE_BSEARCH_KV(TYPE, TABLE, DEFAULT) \ + static TYPE mlib_lookup_kv(rune ch) \ + { \ + ptrdiff_t i, lo, hi; \ + lo = 0; \ + hi = lengthof(TABLE) - 1; \ + i = (lo + hi) / 2; \ + do { \ + if (ch < TABLE[i].k) \ + hi = i - 1; \ + else if (ch > TABLE[i].k) \ + lo = i + 1; \ + else \ + return TABLE[i].v; \ + i = (lo + hi) / 2; \ + } while (lo <= hi); \ + return DEFAULT; \ + } diff --git a/include/unicode/prop.h b/include/unicode/prop.h index 74ffdf9..25bffe7 100644 --- a/include/unicode/prop.h +++ b/include/unicode/prop.h @@ -48,6 +48,7 @@ enum [[clang::flag_enum]] uprop_gc : uint_fast32_t { GC_Z = GC_ZL | GC_ZP | GC_ZS, /* Separator */ }; +[[__nodiscard__, __unsequenced__]] double uprop_get_nv(rune); [[__nodiscard__, __unsequenced__]] enum uprop_gc uprop_get_gc(rune); /* PROP PREDICATES START */ |