UnionFind

Struct UnionFind 

Source
pub struct UnionFind<Key, Parent = IndexedHashMap<Key, Key>, Rank = IndexedHashMap<Key, usize>>
where Key: Copy + PartialEq, Parent: IndexMut<Key, Output = Key>, Rank: IndexMut<Key, Output = usize>,
{ /* private fields */ }
Expand description

A union-find (disjoint-set) struct.

Implementations§

Source§

impl<Key, Parent, Rank> UnionFind<Key, Parent, Rank>
where Key: Copy + PartialEq, Parent: IndexMut<Key, Output = Key>, Rank: IndexMut<Key, Output = usize>,

Source

pub fn make_set(&mut self, x: Key)

Adds the key in it’s own set. The number of sets is increased by 1.

It’s undefined behavior to call this method with a key that is already in a set.

Source

pub fn union(&mut self, x: Key, y: Key)

Joins the sets with the keys x and y. The number of sets is decreased by 1.

§Panics

If x or y is not in any set or if both are in the same set.

Source

pub fn in_same_set(&mut self, x: Key, y: Key) -> bool

Returns true if x and y is in the same set, otherwise false.

§Panics

If x or y is not in any set.

Source

pub fn find_set(&mut self, x: Key) -> Key

Returns the representative of the set that contains x.

§Panics

If x is not in any set.

Source

pub fn num_sets(&self) -> usize

Returns the number of distinct sets.

Source§

impl<K: Copy + Hash + Eq> UnionFind<K>

Source

pub fn new() -> Self

Creates a new UnionFind.

Source§

impl UnionFind<usize, Vec<usize>, Vec<usize>>

Source

pub fn with_keys_in_range(range: RangeTo<usize>) -> Self

Creates a new UnionFindRange with keys in range.

Source

pub fn reset(&mut self)

Reset the struct putting each key in it’s own set.

Trait Implementations§

Source§

impl<Key, Parent, Rank> Clone for UnionFind<Key, Parent, Rank>
where Key: Copy + PartialEq + Clone, Parent: IndexMut<Key, Output = Key> + Clone, Rank: IndexMut<Key, Output = usize> + Clone,

Source§

fn clone(&self) -> UnionFind<Key, Parent, Rank>

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl<Key, Parent, Rank> Freeze for UnionFind<Key, Parent, Rank>
where Parent: Freeze, Rank: Freeze,

§

impl<Key, Parent, Rank> RefUnwindSafe for UnionFind<Key, Parent, Rank>
where Parent: RefUnwindSafe, Rank: RefUnwindSafe, Key: RefUnwindSafe,

§

impl<Key, Parent, Rank> Send for UnionFind<Key, Parent, Rank>
where Parent: Send, Rank: Send, Key: Send,

§

impl<Key, Parent, Rank> Sync for UnionFind<Key, Parent, Rank>
where Parent: Sync, Rank: Sync, Key: Sync,

§

impl<Key, Parent, Rank> Unpin for UnionFind<Key, Parent, Rank>
where Parent: Unpin, Rank: Unpin, Key: Unpin,

§

impl<Key, Parent, Rank> UnwindSafe for UnionFind<Key, Parent, Rank>
where Parent: UnwindSafe, Rank: UnwindSafe, Key: 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> 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 = 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.