pub struct DisjointSetStruct<NI: Idx>(/* private fields */);Expand description
A thread-safe Disjoint Set Struct implementation, that can be safely shared and accessed across threads.
The implementation is based on the Java implementation [1] which in turn is based on a C++ implementation and some input from a Rust implementation [3].
This implementation is tailored for the graph crate as
it needs to support the Idx trait.
Implementations§
Trait Implementations§
Source§impl<NI: Idx> Components<NI> for DisjointSetStruct<NI>
impl<NI: Idx> Components<NI> for DisjointSetStruct<NI>
Source§impl<NI: Idx> UnionFind<NI> for DisjointSetStruct<NI>
impl<NI: Idx> UnionFind<NI> for DisjointSetStruct<NI>
Source§fn union(&self, id1: NI, id2: NI)
fn union(&self, id1: NI, id2: NI)
Joins the set of id1 with the set of id2.
§Examples
use fso_graph::prelude::*;
let dss = DisjointSetStruct::new(10);
dss.union(2, 4);
assert_eq!(dss.find(2), 2);
assert_eq!(dss.find(4), 2);Source§fn find(&self, id: NI) -> NI
fn find(&self, id: NI) -> NI
Find the set of id.
§Examples
use fso_graph::prelude::*;
let dss = DisjointSetStruct::new(10);
assert_eq!(dss.find(4), 4);
dss.union(4, 2);
assert_eq!(dss.find(4), 2);impl<NI: Idx> Send for DisjointSetStruct<NI>
impl<NI: Idx> Sync for DisjointSetStruct<NI>
Auto Trait Implementations§
impl<NI> Freeze for DisjointSetStruct<NI>
impl<NI> !RefUnwindSafe for DisjointSetStruct<NI>
impl<NI> Unpin for DisjointSetStruct<NI>
impl<NI> UnsafeUnpin for DisjointSetStruct<NI>
impl<NI> UnwindSafe for DisjointSetStruct<NI>where
NI: 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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more