From 7c1600dcd9813ca560ecccc5c54877a5750caf4e Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 24 Nov 2018 01:37:11 -0500 Subject: [PATCH] [arrays] Add (unused) SortedUnsizedArrayOf<> --- src/hb-open-type.hh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/hb-open-type.hh b/src/hb-open-type.hh index 0ea884314..eaefc3bc6 100644 --- a/src/hb-open-type.hh +++ b/src/hb-open-type.hh @@ -449,6 +449,27 @@ struct UnsizedOffsetListOf : UnsizedOffsetArrayOf } }; +/* An array with sorted elements. Supports binary searching. */ +template +struct SortedUnsizedArrayOf : UnsizedArrayOf +{ + inline hb_sorted_array_t as_array (unsigned int len) + { return hb_sorted_array (this->arrayZ, len); } + inline hb_sorted_array_t as_array (unsigned int len) const + { return hb_sorted_array (this->arrayZ, len); } + + template + inline Type &bsearch (unsigned int len, const T &x) + { return *as_array (len).bsearch (x, &Crap (Type)); } + template + inline const Type &bsearch (unsigned int len, const T &x) const + { return *as_array (len).bsearch (x, &Null (Type)); } + template + inline bool bfind (unsigned int len, const T &x, unsigned int *i = nullptr) const + { return as_array (len).bfind (x, i); } +}; + + /* An array with a number of elements. */ template struct ArrayOf