Skip to main content

UnionFind

Struct UnionFind 

Source
pub struct UnionFind<C: ?Sized = ()>(/* private fields */);
Expand description

A disjoint-set data structure

Implementations§

Source§

impl<C: ?Sized> UnionFind<C>

Source

pub fn new() -> Self

Construct a new, empty union-find

Source

pub fn len(&self) -> usize

Gets the number of nodes in the union-find

Source

pub fn is_empty(&self) -> bool

Returns true if the union-find has no nodes

Source

pub fn classes(&self) -> Classes<C> ⓘ

Source

pub fn roots(&self) -> Roots<'_, C> ⓘ

Source

pub fn add(&mut self) -> ClassId<C>

Add a new node to the union-find, returning its ID

Source

pub fn parent(&self, key: ClassId<C>) -> Result<ClassId<C>, NoNode>

Source

pub fn find(&self, key: ClassId<C>) -> Result<ClassId<C>, NoNode>

Find the partition root ID for the given node ID, and optimize the search path between the node and its root

§Errors

This method first checks if the node ID is valid, returning an error if no associated node can be found.

Source

pub fn union( &mut self, a: ClassId<C>, b: ClassId<C>, ) -> Result<Unioned<C>, NoNode>

Perform the in-place union of the partitions containing the two given node IDs

§Errors

This method first checks if both node IDs are valid, returning an error if either cannot be found.

Trait Implementations§

Source§

impl<C: ?Sized> Clone for UnionFind<C>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<C: ?Sized> Debug for UnionFind<C>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<C: ?Sized> Default for UnionFind<C>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<C> Freeze for UnionFind<C>
where PhantomData<[ClassId<C>]>: Freeze, C: ?Sized,

§

impl<C> RefUnwindSafe for UnionFind<C>

§

impl<C> Send for UnionFind<C>
where PhantomData<[ClassId<C>]>: Send, C: ?Sized,

§

impl<C> Sync for UnionFind<C>
where PhantomData<[ClassId<C>]>: Sync, C: ?Sized,

§

impl<C> Unpin for UnionFind<C>
where PhantomData<[ClassId<C>]>: Unpin, C: ?Sized,

§

impl<C> UnsafeUnpin for UnionFind<C>

§

impl<C> UnwindSafe for UnionFind<C>
where PhantomData<[ClassId<C>]>: UnwindSafe, C: ?Sized,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.