Skip to main content

UnionFind

Struct UnionFind 

Source
pub struct UnionFind<F>
where F: Fn(usize, usize) -> usize,
{ /* private fields */ }
Expand description

Generic Union-Find with weighted union and per-component character.

Implementations§

Source§

impl<F> UnionFind<F>
where F: Fn(usize, usize) -> usize,

Source

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.

Source

pub fn find(&mut self, x: usize) -> usize

Find the representative of x with path compression.

Source

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.

Source

pub fn are_connected(&mut self, x: usize, y: usize) -> bool

Whether x and y are in the same component.

Source

pub fn get_components(&self) -> usize

Number of distinct components remaining.

Source

pub fn get_root(&mut self, x: usize) -> usize

Representative of x.

Source

pub fn get_character(&mut self, x: usize) -> usize

Character value associated with the component containing x.

Source

pub fn get_size(&mut self, x: usize) -> usize

Size of 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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.