pub struct UnionFind<Value> { /* private fields */ }Expand description
A basic implementation of a union-find datastructure.
Implementations§
Source§impl<Value: NumericId> UnionFind<Value>
impl<Value: NumericId> UnionFind<Value>
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Reset the union-find data-structure to the point where all Ids are their own parents.
Sourcepub fn union(&mut self, a: Value, b: Value) -> (Value, Value)
pub fn union(&mut self, a: Value, b: Value) -> (Value, Value)
Merge two equivalence classes.
Sourcepub fn find_naive(&self, id: Value) -> Value
pub fn find_naive(&self, id: Value) -> Value
Find the representative of an equivalence class without using path compression.
The primary advantage of this method is that it allows the ability to answer find queries
without holding a mutable reference to the union-find.
Source§impl<Value: AtomicNumericId> UnionFind<Value>
impl<Value: AtomicNumericId> UnionFind<Value>
Sourcepub fn with_atomic_access<R>(
&mut self,
max_id: Value,
f: impl FnOnce(&AtomicUnionFindAccess<'_, Value>) -> R,
) -> R
pub fn with_atomic_access<R>( &mut self, max_id: Value, f: impl FnOnce(&AtomicUnionFindAccess<'_, Value>) -> R, ) -> R
Temporarily borrow this union-find as a fixed-capacity atomic view.
The backing vector is grown before the atomic view is created and
cannot resize while f runs. Atomic and ordinary accesses never
overlap: the mutable receiver excludes ordinary readers until f and
every scoped worker borrowing its view have completed. No allocation,
resize, or per-operation access guard occurs while the view is active.
max_id is inclusive, and f must not request a union containing a
larger ID.
§Panics
Panics if the ID and its atomic integer do not have identical size and alignment on the target platform.