From 85757cb98d9ab1fa238fba6f9dc331bd035fa8c0 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Mon, 5 Aug 2024 13:50:06 -0400 Subject: [PATCH] BLI: Return number of roots in disjoint set reduction --- source/blender/blenlib/BLI_atomic_disjoint_set.hh | 3 ++- source/blender/blenlib/intern/atomic_disjoint_set.cc | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/source/blender/blenlib/BLI_atomic_disjoint_set.hh b/source/blender/blenlib/BLI_atomic_disjoint_set.hh index 4694e63dfcf..011e5822847 100644 --- a/source/blender/blenlib/BLI_atomic_disjoint_set.hh +++ b/source/blender/blenlib/BLI_atomic_disjoint_set.hh @@ -141,8 +141,9 @@ class AtomicDisjointSet { * Get an identifier for each id. This is deterministic and does not depend on the order of * joins. The ids are ordered by their first occurrence. Consequently, `result[0]` is always zero * (unless there are no elements). + * \return The total number of unique IDs. */ - void calc_reduced_ids(MutableSpan result) const; + int calc_reduced_ids(MutableSpan result) const; /** * Count the number of disjoint sets. diff --git a/source/blender/blenlib/intern/atomic_disjoint_set.cc b/source/blender/blenlib/intern/atomic_disjoint_set.cc index 6ebdbfb8892..39723914aaa 100644 --- a/source/blender/blenlib/intern/atomic_disjoint_set.cc +++ b/source/blender/blenlib/intern/atomic_disjoint_set.cc @@ -31,7 +31,7 @@ static void update_first_occurrence(Map &map, const int root, const in }); } -void AtomicDisjointSet::calc_reduced_ids(MutableSpan result) const +int AtomicDisjointSet::calc_reduced_ids(MutableSpan result) const { BLI_assert(result.size() == items_.size()); @@ -88,6 +88,7 @@ void AtomicDisjointSet::calc_reduced_ids(MutableSpan result) const result[i] = id_by_root.lookup(result[i]); } }); + return id_by_root.size(); } int AtomicDisjointSet::count_sets() const