pub struct UnionFind { /* private fields */ }Expand description
Implement union-find for elements with indices [0, …, N-1].
Implementations§
Source§impl UnionFind
impl UnionFind
Sourcepub fn new(size: i32) -> UnionFind
pub fn new(size: i32) -> UnionFind
Create new union-find data where initially each element is a separate component.
Sourcepub fn representative(&mut self, element: i32) -> i32
pub fn representative(&mut self, element: i32) -> i32
Return the index of the current representative of the component the element belong to.
This mutates the data, as it needs to modify the representatives to short-cut further lookups.
Sourcepub fn merge(&mut self, left: i32, right: i32)
pub fn merge(&mut self, left: i32, right: i32)
Merge the two distinct components the left and right elements belong to.
Sourcepub fn components(&self) -> i32
pub fn components(&self) -> i32
The current number of distinct components.
Auto Trait Implementations§
impl Freeze for UnionFind
impl RefUnwindSafe for UnionFind
impl Send for UnionFind
impl Sync for UnionFind
impl Unpin for UnionFind
impl UnwindSafe for UnionFind
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more