pub struct UnionFind { /* private fields */ }Expand description
Union-Find data structure with path compression and union by rank.
Implementations§
Source§impl UnionFind
impl UnionFind
Sourcepub fn num_components(&self) -> usize
pub fn num_components(&self) -> usize
Number of disjoint components.
Sourcepub fn find(&mut self, x: NodeId) -> NodeId
pub fn find(&mut self, x: NodeId) -> NodeId
Find representative of node’s component with path compression.
Sourcepub fn union(&mut self, x: NodeId, y: NodeId) -> bool
pub fn union(&mut self, x: NodeId, y: NodeId) -> bool
Union two components by rank.
Returns true if a merge occurred (x and y were in different components).
Sourcepub fn connected(&mut self, x: NodeId, y: NodeId) -> bool
pub fn connected(&mut self, x: NodeId, y: NodeId) -> bool
Check if two nodes are in the same component.
Sourcepub fn component_ids(&mut self) -> Vec<ComponentId>
pub fn component_ids(&mut self) -> Vec<ComponentId>
Get component ID for each node.
Returns a vector where result[i] is the component ID of node i.
Component IDs are assigned 0, 1, 2, … based on root nodes.
Sourcepub fn component_size(&mut self, x: NodeId) -> usize
pub fn component_size(&mut self, x: NodeId) -> usize
Get the size of the component containing node 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 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