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
,QuickUnion
T
- Any unsigned integral types, e.g.,u8
,u16
,u32
,u64
,usize
or any type that implementsVertexType
N
- 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> UnionFind<'a, QuickUnion<BySize<true>>, T, N>where
T: VertexType,
impl<'a, T, const N: usize> UnionFind<'a, QuickUnion<BySize<true>>, T, N>where
T: VertexType,
source§impl<'a, T, const N: usize> UnionFind<'a, QuickUnion<ByRank<true>>, T, N>where
T: VertexType,
impl<'a, T, const N: usize> UnionFind<'a, QuickUnion<ByRank<true>>, T, N>where
T: VertexType,
source§impl<'a, T, const N: usize, const PATH_COMPRESS: bool> UnionFind<'a, QuickUnion<Unweighted<true>, PATH_COMPRESS>, T, N>where
T: VertexType,
impl<'a, T, const N: usize, const PATH_COMPRESS: bool> UnionFind<'a, QuickUnion<Unweighted<true>, PATH_COMPRESS>, T, N>where
T: VertexType,
source§impl<'a, A, T, const N: usize> UnionFind<'a, A, T, N>where
T: VertexType,
A: AlgorithmContainer + Union<T> + Find<T> + Connected<T>,
impl<'a, A, T, const N: usize> UnionFind<'a, A, T, N>where
T: VertexType,
A: AlgorithmContainer + Union<T> + 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