mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-20 14:31:10 +01:00
[set] Add test_and_add / test_and_del
Use in graph.
This commit is contained in:
1 parent
7f1ff9c881
commit
de1237fbf2
5 files changed
+50
-12
No files matched your search
+5
-12
@@ -762,16 +762,14 @@ struct graph_t
|
||||
|
||||
void find_subgraph (unsigned node_idx, hb_set_t& subgraph)
|
||||
{
|
||||
if (subgraph.has (node_idx)) return;
|
||||
subgraph.add (node_idx);
|
||||
if (!subgraph.test_and_add (node_idx)) return;
|
||||
for (const auto& link : vertices_[node_idx].obj.all_links ())
|
||||
find_subgraph (link.objidx, subgraph);
|
||||
}
|
||||
|
||||
size_t find_subgraph_size (unsigned node_idx, hb_set_t& subgraph, unsigned max_depth = -1)
|
||||
{
|
||||
if (subgraph.has (node_idx)) return 0;
|
||||
subgraph.add (node_idx);
|
||||
if (!subgraph.test_and_add (node_idx)) return 0;
|
||||
|
||||
const auto& o = vertices_[node_idx].obj;
|
||||
size_t size = o.tail - o.head;
|
||||
@@ -1159,8 +1157,7 @@ struct graph_t
|
||||
hb_set_t visited;
|
||||
for (unsigned p : vertices_[node_idx].parents)
|
||||
{
|
||||
if (visited.has (p)) continue;
|
||||
visited.add (p);
|
||||
if (!visited.test_and_add (p)) continue;
|
||||
|
||||
// Only real links can be wide
|
||||
for (const auto& l : vertices_[p].obj.real_links)
|
||||
@@ -1364,14 +1361,10 @@ struct graph_t
|
||||
hb_set_t& connected)
|
||||
{
|
||||
if (unlikely (!check_success (!visited.in_error ()))) return;
|
||||
if (visited.has (start_idx)) return;
|
||||
visited.add (start_idx);
|
||||
if (!visited.test_and_add (start_idx)) return;
|
||||
|
||||
if (targets.has (start_idx))
|
||||
{
|
||||
targets.del (start_idx);
|
||||
if (targets.test_and_del (start_idx))
|
||||
connected.add (start_idx);
|
||||
}
|
||||
|
||||
const auto& v = vertices_[start_idx];
|
||||
|
||||
|
||||
@@ -115,6 +115,31 @@ struct hb_bit_page_t
|
||||
void set (hb_codepoint_t g, bool value) { if (value) add (g); else del (g); }
|
||||
bool get (hb_codepoint_t g) const { return elt (g) & mask (g); }
|
||||
|
||||
bool test_and_add (hb_codepoint_t g)
|
||||
{
|
||||
elt_t *e = &elt (g);
|
||||
elt_t m = mask (g);
|
||||
|
||||
bool ret = !(*e & m);
|
||||
if (ret)
|
||||
{
|
||||
*e |= m; dirty ();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
bool test_and_del (hb_codepoint_t g)
|
||||
{
|
||||
elt_t *e = &elt (g);
|
||||
elt_t m = mask (g);
|
||||
|
||||
bool ret = *e & m;
|
||||
if (ret)
|
||||
{
|
||||
*e &= ~m; dirty ();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void add_range (hb_codepoint_t a, hb_codepoint_t b)
|
||||
{
|
||||
elt_t *la = &elt (a);
|
||||
|
||||
@@ -104,6 +104,8 @@ struct hb_bit_set_invertible_t
|
||||
|
||||
|
||||
void add (hb_codepoint_t g) { unlikely (inverted) ? s.del (g) : s.add (g); }
|
||||
bool test_and_add (hb_codepoint_t g) { return unlikely (inverted) ? s.test_and_del (g) : s.test_and_add (g); }
|
||||
bool test_and_del (hb_codepoint_t g) { return unlikely (inverted) ? s.test_and_add (g) : s.test_and_del (g); }
|
||||
bool add_range (hb_codepoint_t a, hb_codepoint_t b)
|
||||
{ return unlikely (inverted) ? ((void) s.del_range (a, b), true) : s.add_range (a, b); }
|
||||
|
||||
|
||||
@@ -154,6 +154,22 @@ struct hb_bit_set_t
|
||||
page_t *page = page_for (g, true); if (unlikely (!page)) return;
|
||||
page->add (g);
|
||||
}
|
||||
bool test_and_add (hb_codepoint_t g)
|
||||
{
|
||||
if (unlikely (!successful)) return false;
|
||||
if (unlikely (g == INVALID)) return false;
|
||||
dirty ();
|
||||
page_t *page = page_for (g, true); if (unlikely (!page)) return false;
|
||||
return page->test_and_add (g);
|
||||
}
|
||||
bool test_and_del (hb_codepoint_t g)
|
||||
{
|
||||
if (unlikely (!successful)) return false;
|
||||
if (unlikely (g == INVALID)) return false;
|
||||
dirty ();
|
||||
page_t *page = page_for (g); if (!page) return false;
|
||||
return page->test_and_del (g);
|
||||
}
|
||||
bool add_range (hb_codepoint_t a, hb_codepoint_t b)
|
||||
{
|
||||
if (unlikely (!successful)) return true; /* https://github.com/harfbuzz/harfbuzz/issues/657 */
|
||||
|
||||
@@ -84,6 +84,8 @@ struct hb_sparseset_t
|
||||
uint32_t hash () const { return s.hash (); }
|
||||
|
||||
void add (hb_codepoint_t g) { s.add (g); }
|
||||
bool test_and_add (hb_codepoint_t g) { return s.test_and_add (g); }
|
||||
bool test_and_del (hb_codepoint_t g) { return s.test_and_del (g); }
|
||||
bool add_range (hb_codepoint_t a, hb_codepoint_t b) { return s.add_range (a, b); }
|
||||
|
||||
template <typename T>
|
||||
|
||||
Reference in new issue
Block a user