From 8aa92ff8f054a1b7b8d06618a6366a44cba8fe87 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 18 Aug 2021 23:01:06 -0600 Subject: [PATCH] [bit-set-invertible] Implement get_min/max --- src/hb-bit-set-invertible.hh | 4 ++-- src/hb-bit-set.hh | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/hb-bit-set-invertible.hh b/src/hb-bit-set-invertible.hh index 5a4c3425c..5d1c9f566 100644 --- a/src/hb-bit-set-invertible.hh +++ b/src/hb-bit-set-invertible.hh @@ -146,9 +146,9 @@ struct hb_bit_set_invertible_t { return inverted ? INVALID - s.get_population () : s.get_population (); } hb_codepoint_t get_min () const - { return /*XXX(inverted)*/s.get_min (); } + { return s.get_min (inverted); } hb_codepoint_t get_max () const - { return /*XXX(inverted)*/s.get_max (); } + { return inverted ? /*XXX*/ INVALID - 1 : s.get_max (); } static constexpr hb_codepoint_t INVALID = hb_bit_set_t::INVALID; diff --git a/src/hb-bit-set.hh b/src/hb-bit-set.hh index 265a295c9..5f38f4eaf 100644 --- a/src/hb-bit-set.hh +++ b/src/hb-bit-set.hh @@ -711,16 +711,26 @@ struct hb_bit_set_t population = pop; return pop; } - hb_codepoint_t get_min () const + hb_codepoint_t get_min (bool inverted = false) const { + unsigned last_major = (unsigned) -1; + unsigned count = pages.length; for (unsigned i = 0; i < count; i++) { const auto& map = page_map[i]; const auto& page = pages[map.index]; - if (!page.is_empty ()) - return map.major * page_t::PAGE_BITS + page.get_min (); + if (inverted) + { + if (last_major + 1 != map.major) + return (last_major + 1) * page_t::PAGE_BITS; + + last_major = map.major; + } + + if (!page.is_empty (inverted)) + return map.major * page_t::PAGE_BITS + page.get_min (inverted); } return INVALID; }