pub struct UnionFind<F>{ /* private fields */ }Expand description
Generic Union-Find with weighted union and per-component character.
Implementations§
Source§impl<F> UnionFind<F>
impl<F> UnionFind<F>
Sourcepub fn new(n: usize, op: F, init: usize) -> Self
pub fn new(n: usize, op: F, init: usize) -> Self
Build a Union-Find over the indices 0..=n. The closure op defines how
character values combine during union. init seeds every component’s
character.
Sourcepub fn union(&mut self, x: usize, y: usize, w: usize) -> bool
pub fn union(&mut self, x: usize, y: usize, w: usize) -> bool
Union the components of x and y, combining characters via op and w.
Returns true if a merge happened, false if x and y were already
in the same component.
Sourcepub fn are_connected(&mut self, x: usize, y: usize) -> bool
pub fn are_connected(&mut self, x: usize, y: usize) -> bool
Whether x and y are in the same component.
Sourcepub fn get_components(&self) -> usize
pub fn get_components(&self) -> usize
Number of distinct components remaining.
Sourcepub fn get_character(&mut self, x: usize) -> usize
pub fn get_character(&mut self, x: usize) -> usize
Character value associated with the component containing x.
Auto Trait Implementations§
impl<F> Freeze for UnionFind<F>where
F: Freeze,
impl<F> RefUnwindSafe for UnionFind<F>where
F: RefUnwindSafe,
impl<F> Send for UnionFind<F>where
F: Send,
impl<F> Sync for UnionFind<F>where
F: Sync,
impl<F> Unpin for UnionFind<F>where
F: Unpin,
impl<F> UnsafeUnpin for UnionFind<F>where
F: UnsafeUnpin,
impl<F> UnwindSafe for UnionFind<F>where
F: 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