diff options
author | Behdad Esfahbod <behdad@behdad.org> | 2018-11-24 01:37:11 -0500 |
---|---|---|
committer | Behdad Esfahbod <behdad@behdad.org> | 2018-11-24 09:48:06 -0500 |
commit | 7c1600dcd9813ca560ecccc5c54877a5750caf4e (patch) | |
tree | 4057e1aaef824b14b0fa751db9099a601b53dcc3 /src/hb-open-type.hh | |
parent | e700392f5cbf366f1e03dc7e7b1a2eb6c3027b92 (diff) |
[arrays] Add (unused) SortedUnsizedArrayOf<>
Diffstat (limited to 'src/hb-open-type.hh')
-rw-r--r-- | src/hb-open-type.hh | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/hb-open-type.hh b/src/hb-open-type.hh index 0ea88431..eaefc3bc 100644 --- a/src/hb-open-type.hh +++ b/src/hb-open-type.hh @@ -449,6 +449,27 @@ struct UnsizedOffsetListOf : UnsizedOffsetArrayOf<Type, OffsetType, has_null> } }; +/* An array with sorted elements. Supports binary searching. */ +template <typename Type> +struct SortedUnsizedArrayOf : UnsizedArrayOf<Type> +{ + inline hb_sorted_array_t<Type> as_array (unsigned int len) + { return hb_sorted_array (this->arrayZ, len); } + inline hb_sorted_array_t<const Type> as_array (unsigned int len) const + { return hb_sorted_array (this->arrayZ, len); } + + template <typename T> + inline Type &bsearch (unsigned int len, const T &x) + { return *as_array (len).bsearch (x, &Crap (Type)); } + template <typename T> + inline const Type &bsearch (unsigned int len, const T &x) const + { return *as_array (len).bsearch (x, &Null (Type)); } + template <typename T> + 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 <typename Type, typename LenType=HBUINT16> struct ArrayOf |