pub struct DisjointSets(/* private fields */);Expand description
Disjoint sets over 0..n, the lowest member of a set its root, so a
numbering derived from the roots depends on the elements’ order and on
nothing else.
use arris_math::DisjointSets;
let mut sets = DisjointSets::new(5);
assert!(sets.union(3, 1));
assert!(sets.union(4, 3));
assert!(!sets.union(1, 4)); // already together
assert_eq!((sets.find(4), sets.find(3), sets.find(2)), (1, 1, 2));Implementations§
Source§impl DisjointSets
impl DisjointSets
Sourcepub fn find(&mut self, i: usize) -> usize
pub fn find(&mut self, i: usize) -> usize
The root of i’s set: its lowest member. Halves the path it walks.
Panics if i is not below the n of DisjointSets::new: an
index is the caller’s own, never geometry.
Trait Implementations§
Source§impl Clone for DisjointSets
impl Clone for DisjointSets
Auto Trait Implementations§
impl Freeze for DisjointSets
impl RefUnwindSafe for DisjointSets
impl Send for DisjointSets
impl Sync for DisjointSets
impl Unpin for DisjointSets
impl UnsafeUnpin for DisjointSets
impl UnwindSafe for DisjointSets
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.