Skip to main content

UnionFind

Struct UnionFind 

Source
pub struct UnionFind<T: Hash + Eq + Clone> { /* private fields */ }
Expand description

Disjoint-set union–find with union by rank and path compression.

Implementations§

Source§

impl<T: Hash + Eq + Clone> UnionFind<T>

Source

pub fn new(elements: impl IntoIterator<Item = T>) -> Self

Create a new union–find structure for the given elements.

Source

pub fn find(&mut self, x: &T) -> Result<T, Error>

Return the representative of the set containing x.

Source

pub fn union(&mut self, x: &T, y: &T) -> Result<bool, Error>

Merge the sets containing x and y.

Source

pub fn connected(&mut self, x: &T, y: &T) -> Result<bool, Error>

Return whether x and y are in the same set.

Source

pub fn count(&mut self) -> usize

Return the current number of disjoint sets.

Auto Trait Implementations§

§

impl<T> Freeze for UnionFind<T>
where HashMap<T, T>: Freeze, HashMap<T, u32>: Freeze,

§

impl<T> RefUnwindSafe for UnionFind<T>

§

impl<T> Send for UnionFind<T>
where HashMap<T, T>: Send, HashMap<T, u32>: Send,

§

impl<T> Sync for UnionFind<T>
where HashMap<T, T>: Sync, HashMap<T, u32>: Sync,

§

impl<T> Unpin for UnionFind<T>
where HashMap<T, T>: Unpin, HashMap<T, u32>: Unpin,

§

impl<T> UnsafeUnpin for UnionFind<T>

§

impl<T> UnwindSafe for UnionFind<T>

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.