pub struct UnionFind<'a, A, T, const N: usize>where
T: VertexType + 'a,
A: AlgorithmContainer,{ /* private fields */ }Expand description
UnionFind data structure
This data structure stores a collection of disjoint (non-overlapping) sets.
UnionFind is parameterized by the following
A- Algorithm, e.g.,QuickFind,QuickUnionT- Any unsigned integral types, e.g.,u8,u16,u32,u64,usizeor any type that implementsVertexTypeN- Constant size of internal representative buffer
§Example
use pulau_rs::{UnionFind, QuickFind, QuickUnion};
fn make_uf_quickfind() {
// construct with quickfind algorithm with fixed size 10
let mut uf = UnionFind::<QuickFind, u32, 10>::default();
}
fn make_uf_quickunion() {
// construct with weighted quickunion with path compression algorithm with fixed size 10
let mut uf = UnionFind::<QuickUnion, u32, 10>::default();
}§Size Guarantees
Size of UnionFind depends on whether the algorithm you have chosen is weighted
Assuming no padding,
If it’s weighted then, size of UnionFind is T * N + size_of(usize) * N
Else it will be T * N
If you are using borrowed buffers, then the size will be the core::mem::size_of::<usize>() * 2
if it’s weighted, else it will just be core::mem::size_of::<usize>()
Implementations§
Source§impl<'a, T, const N: usize, const P: bool> UnionFind<'a, QuickUnion<ByRank<Borrowed<Fat>>, P>, T, N>where
T: VertexType,
impl<'a, T, const N: usize, const P: bool> UnionFind<'a, QuickUnion<ByRank<Borrowed<Fat>>, P>, T, N>where
T: VertexType,
Source§impl<'a, T, const N: usize, const P: bool> UnionFind<'a, QuickUnion<ByRank<Borrowed<Thin>>, P>, T, N>where
T: VertexType,
impl<'a, T, const N: usize, const P: bool> UnionFind<'a, QuickUnion<ByRank<Borrowed<Thin>>, P>, T, N>where
T: VertexType,
Source§impl<'a, T, const N: usize, const P: bool> UnionFind<'a, QuickUnion<BySize<Borrowed<Fat>>, P>, T, N>where
T: VertexType,
impl<'a, T, const N: usize, const P: bool> UnionFind<'a, QuickUnion<BySize<Borrowed<Fat>>, P>, T, N>where
T: VertexType,
Source§impl<'a, T, const N: usize, const P: bool> UnionFind<'a, QuickUnion<BySize<Borrowed<Thin>>, P>, T, N>where
T: VertexType,
impl<'a, T, const N: usize, const P: bool> UnionFind<'a, QuickUnion<BySize<Borrowed<Thin>>, P>, T, N>where
T: VertexType,
Source§impl<'a, T, const N: usize, const P: bool> UnionFind<'a, QuickUnion<Unweighted<Borrowed<Fat>>, P>, T, N>where
T: VertexType,
impl<'a, T, const N: usize, const P: bool> UnionFind<'a, QuickUnion<Unweighted<Borrowed<Fat>>, P>, T, N>where
T: VertexType,
Source§impl<'a, T, const N: usize, const P: bool> UnionFind<'a, QuickUnion<Unweighted<Borrowed<Thin>>, P>, T, N>where
T: VertexType,
impl<'a, T, const N: usize, const P: bool> UnionFind<'a, QuickUnion<Unweighted<Borrowed<Thin>>, P>, T, N>where
T: VertexType,
Source§impl<'a, R, T, const N: usize, const P: bool> UnionFind<'a, QuickUnion<ByRandom<R, Borrowed<Fat>>, P>, T, N>
impl<'a, R, T, const N: usize, const P: bool> UnionFind<'a, QuickUnion<ByRandom<R, Borrowed<Fat>>, P>, T, N>
Source§impl<'a, R, T, const N: usize, const P: bool> UnionFind<'a, QuickUnion<ByRandom<R, Borrowed<Thin>>, P>, T, N>
impl<'a, R, T, const N: usize, const P: bool> UnionFind<'a, QuickUnion<ByRandom<R, Borrowed<Thin>>, P>, T, N>
Source§impl<R, const N: usize, const P: bool> UnionFind<'_, QuickUnion<ByRandom<R, Owned>, P>, u8, N>where
R: RngCore,
impl<R, const N: usize, const P: bool> UnionFind<'_, QuickUnion<ByRandom<R, Owned>, P>, u8, N>where
R: RngCore,
Source§impl<R, const N: usize, const P: bool> UnionFind<'_, QuickUnion<ByRandom<R, Owned>, P>, u16, N>where
R: RngCore,
impl<R, const N: usize, const P: bool> UnionFind<'_, QuickUnion<ByRandom<R, Owned>, P>, u16, N>where
R: RngCore,
Source§impl<R, const N: usize, const P: bool> UnionFind<'_, QuickUnion<ByRandom<R, Owned>, P>, u32, N>where
R: RngCore,
impl<R, const N: usize, const P: bool> UnionFind<'_, QuickUnion<ByRandom<R, Owned>, P>, u32, N>where
R: RngCore,
Source§impl<R, const N: usize, const P: bool> UnionFind<'_, QuickUnion<ByRandom<R, Owned>, P>, u64, N>where
R: RngCore,
impl<R, const N: usize, const P: bool> UnionFind<'_, QuickUnion<ByRandom<R, Owned>, P>, u64, N>where
R: RngCore,
Source§impl<R, const N: usize, const P: bool> UnionFind<'_, QuickUnion<ByRandom<R, Owned>, P>, usize, N>where
R: RngCore,
impl<R, const N: usize, const P: bool> UnionFind<'_, QuickUnion<ByRandom<R, Owned>, P>, usize, N>where
R: RngCore,
Source§impl<'a, A, T, const N: usize> UnionFind<'a, A, T, N>where
T: VertexType,
A: AlgorithmContainer + Union<T, A::HeuristicKind<'a>> + Find<T> + Connected<T>,
impl<'a, A, T, const N: usize> UnionFind<'a, A, T, N>where
T: VertexType,
A: AlgorithmContainer + Union<T, A::HeuristicKind<'a>> + Find<T> + Connected<T>,
Sourcepub fn connected(&mut self, a: T::IdentifierType, b: T::IdentifierType) -> bool
pub fn connected(&mut self, a: T::IdentifierType, b: T::IdentifierType) -> bool
Checks whether 2 nodes are connected to each other
Sourcepub fn find(&mut self, a: T::IdentifierType) -> T
pub fn find(&mut self, a: T::IdentifierType) -> T
Finds a node
Sourcepub fn union_sets(&mut self, a: T::IdentifierType, b: T::IdentifierType)
pub fn union_sets(&mut self, a: T::IdentifierType, b: T::IdentifierType)
Unions 2 node. If those 2 nodes are already part of the same component then this does nothing
Sourcepub fn representative(&self) -> &A::RepresentativeContainer<'a, T, N>
pub fn representative(&self) -> &A::RepresentativeContainer<'a, T, N>
Gets the representative slice
Sourcepub fn heuristic(&self) -> &A::HeuristicContainer<'a, N>
pub fn heuristic(&self) -> &A::HeuristicContainer<'a, N>
Gets the heuristic slice
Trait Implementations§
Source§impl<const N: usize, const P: bool> Default for UnionFind<'_, QuickUnion<Unweighted, P>, u16, N>
impl<const N: usize, const P: bool> Default for UnionFind<'_, QuickUnion<Unweighted, P>, u16, N>
Source§impl<const N: usize, const P: bool> Default for UnionFind<'_, QuickUnion<Unweighted, P>, u32, N>
impl<const N: usize, const P: bool> Default for UnionFind<'_, QuickUnion<Unweighted, P>, u32, N>
Source§impl<const N: usize, const P: bool> Default for UnionFind<'_, QuickUnion<Unweighted, P>, u64, N>
impl<const N: usize, const P: bool> Default for UnionFind<'_, QuickUnion<Unweighted, P>, u64, N>
Source§impl<const N: usize, const P: bool> Default for UnionFind<'_, QuickUnion<Unweighted, P>, u8, N>
impl<const N: usize, const P: bool> Default for UnionFind<'_, QuickUnion<Unweighted, P>, u8, N>
Source§impl<const N: usize, const P: bool> Default for UnionFind<'_, QuickUnion<Unweighted, P>, usize, N>
impl<const N: usize, const P: bool> Default for UnionFind<'_, QuickUnion<Unweighted, P>, usize, N>
Auto Trait Implementations§
impl<'a, A, T, const N: usize> Freeze for UnionFind<'a, A, T, N>where
<A as AlgorithmContainer>::RepresentativeContainer<'a, T, N>: Freeze,
<A as AlgorithmContainer>::HeuristicContainer<'a, N>: Freeze,
<A as AlgorithmContainer>::RngKind<'a>: Freeze,
impl<'a, A, T, const N: usize> RefUnwindSafe for UnionFind<'a, A, T, N>where
<A as AlgorithmContainer>::RepresentativeContainer<'a, T, N>: RefUnwindSafe,
<A as AlgorithmContainer>::HeuristicContainer<'a, N>: RefUnwindSafe,
<A as AlgorithmContainer>::RngKind<'a>: RefUnwindSafe,
A: RefUnwindSafe,
impl<'a, A, T, const N: usize> Send for UnionFind<'a, A, T, N>where
<A as AlgorithmContainer>::RepresentativeContainer<'a, T, N>: Send,
<A as AlgorithmContainer>::HeuristicContainer<'a, N>: Send,
<A as AlgorithmContainer>::RngKind<'a>: Send,
A: Send,
impl<'a, A, T, const N: usize> Sync for UnionFind<'a, A, T, N>where
<A as AlgorithmContainer>::RepresentativeContainer<'a, T, N>: Sync,
<A as AlgorithmContainer>::HeuristicContainer<'a, N>: Sync,
<A as AlgorithmContainer>::RngKind<'a>: Sync,
A: Sync,
impl<'a, A, T, const N: usize> Unpin for UnionFind<'a, A, T, N>where
<A as AlgorithmContainer>::RepresentativeContainer<'a, T, N>: Unpin,
<A as AlgorithmContainer>::HeuristicContainer<'a, N>: Unpin,
<A as AlgorithmContainer>::RngKind<'a>: Unpin,
A: Unpin,
impl<'a, A, T, const N: usize> UnwindSafe for UnionFind<'a, A, T, N>where
<A as AlgorithmContainer>::RepresentativeContainer<'a, T, N>: UnwindSafe,
<A as AlgorithmContainer>::HeuristicContainer<'a, N>: UnwindSafe,
<A as AlgorithmContainer>::RngKind<'a>: UnwindSafe,
A: 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