[set] Speed up may_intersect()

This commit is contained in:
Behdad Esfahbod 2025-02-04 22:02:11 +00:00
parent a617328005
commit 255dadc152
4 changed files with 32 additions and 6 deletions

View file

@ -227,6 +227,13 @@ struct hb_bit_page_t
return false;
return true;
}
bool may_intersect (const hb_bit_page_t &other) const
{
for (unsigned i = 0; i < len (); i++)
if (v[i] & other.v[i])
return true;
return false;
}
bool operator <= (const hb_bit_page_t &larger_page) const { return is_subset (larger_page); }
bool is_subset (const hb_bit_page_t &larger_page) const
{

View file

@ -139,6 +139,9 @@ struct hb_bit_set_invertible_t
hb_bit_set_invertible_t& operator << (const hb_codepoint_pair_t& range)
{ add_range (range.first, range.second); return *this; }
bool may_intersect (const hb_bit_set_invertible_t &other) const
{ return inverted || other.inverted || s.may_intersect (other.s); }
bool intersects (hb_codepoint_t first, hb_codepoint_t last) const
{
hb_codepoint_t c = first - 1;

View file

@ -358,6 +358,26 @@ struct hb_bit_set_t
hb_bit_set_t& operator << (const hb_codepoint_pair_t& range)
{ add_range (range.first, range.second); return *this; }
bool may_intersect (const hb_bit_set_t &other) const
{
unsigned int na = pages.length;
unsigned int nb = other.pages.length;
unsigned int a = 0, b = 0;
for (; a < na && b < nb; )
{
if (page_map.arrayZ[a].major == other.page_map.arrayZ[b].major &&
page_at (a).may_intersect (other.page_at (b)))
return true;
if (page_map.arrayZ[a].major < other.page_map.arrayZ[b].major)
a++;
else
b++;
}
return false;
}
bool intersects (hb_codepoint_t first, hb_codepoint_t last) const
{
hb_codepoint_t c = first - 1;

View file

@ -120,12 +120,8 @@ struct hb_sparseset_t
hb_sparseset_t& operator << (const hb_codepoint_pair_t& range)
{ add_range (range.first, range.second); return *this; }
bool may_intersect (const hb_set_t &other) const
{
hb_sparseset_t tmp = *this;
tmp.intersect (other);
return !tmp.is_empty ();
}
bool may_intersect (const hb_sparseset_t &other) const
{ return s.may_intersect (other.s); }
bool intersects (hb_codepoint_t first, hb_codepoint_t last) const
{ return s.intersects (first, last); }