pub struct UnionFind { /* private fields */ }Expand description
A simple disjoint-set (union-find) data structure over integer IDs.
Implementations§
Source§impl UnionFind
impl UnionFind
Sourcepub fn find(&mut self, x: usize) -> usize
pub fn find(&mut self, x: usize) -> usize
Find the representative of the component containing x (path compression).
Sourcepub fn union(&mut self, x: usize, y: usize) -> bool
pub fn union(&mut self, x: usize, y: usize) -> bool
Union the components containing x and y. Returns true if they were separate.
Sourcepub fn same(&mut self, x: usize, y: usize) -> bool
pub fn same(&mut self, x: usize, y: usize) -> bool
Check whether x and y are in the same component.
Sourcepub fn component_count(&mut self) -> usize
pub fn component_count(&mut self) -> usize
Count the number of distinct components.
Sourcepub fn component_of(&mut self, x: usize) -> Vec<usize>
pub fn component_of(&mut self, x: usize) -> Vec<usize>
Collect all elements in the same component as x.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for UnionFind
impl RefUnwindSafe for UnionFind
impl Send for UnionFind
impl Sync for UnionFind
impl Unpin for UnionFind
impl UnsafeUnpin 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