pub struct DisjointSets<T: NodeTrait> { /* private fields */ }
Expand description
A collection of disjoint sets over cheaply-cloned objects.
Implementations§
Source§impl<T: NodeTrait> DisjointSets<T>
impl<T: NodeTrait> DisjointSets<T>
Sourcepub fn find(&mut self, v: T) -> Option<T>
pub fn find(&mut self, v: T) -> Option<T>
Finds the canonical representative of the set to which v
belongs, if
v
in fact has been added via a call to DisjointSets::add
.
Sourcepub fn union(&mut self, a: T, b: T, by_rank: bool) -> Option<T>
pub fn union(&mut self, a: T, b: T, by_rank: bool) -> Option<T>
Merges the sets to which a
and b
belong to, returning their new
canonical representative. If by_rank
is true
, the union-by-rank
optimization is used, acheiving near-linear time complexity.
Otherwise, the canonical representative of b
is chosen as the new
canonical representative, which leads to log-linear complexity.
Trait Implementations§
Source§impl<T> Debug for DisjointSets<T>
impl<T> Debug for DisjointSets<T>
Auto Trait Implementations§
impl<T> Freeze for DisjointSets<T>
impl<T> RefUnwindSafe for DisjointSets<T>where
T: RefUnwindSafe,
impl<T> Send for DisjointSets<T>where
T: Send,
impl<T> Sync for DisjointSets<T>where
T: Sync,
impl<T> Unpin for DisjointSets<T>where
T: Unpin,
impl<T> UnwindSafe for DisjointSets<T>where
T: UnwindSafe,
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