Struct disjoint_sets::UnionFind [] [src]

pub struct UnionFind<E: ElementType = usize> {
    // some fields omitted
}

Array-based union-find representing a set of disjoint sets.

Methods

impl<E: ElementType> UnionFind<E>
[src]

fn new(size: usize) -> Self

Creates a new union-find of size elements.

Panics

If size elements would overflow the element type E.

fn len(&self) -> usize

The number of elements in all the sets.

fn is_empty(&self) -> bool

Is the union-find devoid of elements?

It is possible to create an empty UnionFind and then add elements with alloc.

fn alloc(&mut self) -> E

Creates a new element in a singleton set.

Panics

If allocating another element would overflow the element type E.

fn union(&mut self, a: E, b: E) -> bool

Joins the sets of the two given elements.

Returns whether anything changed. That is, if the sets were different, it returns true, but if they were already the same then it returns false.

fn find(&self, element: E) -> E

Finds the representative element for the given element’s set.

fn equiv(&self, a: E, b: E) -> bool

Determines whether two elements are in the same set.

fn force(&self)

Forces all laziness, so that each element points directly to its set’s representative.

fn as_vec(&self) -> Vec<E>

Returns a vector of set representatives.

Trait Implementations

impl<E: Clone + ElementType> Clone for UnionFind<E>
[src]

fn clone(&self) -> UnionFind<E>

Returns a copy of the value. Read more

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

Performs copy-assignment from source. Read more

impl<E: Debug + ElementType> Debug for UnionFind<E>
[src]

fn fmt(&self, formatter: &mut Formatter) -> Result

Formats the value using the given formatter.

impl<E: ElementType> Default for UnionFind<E>
[src]

fn default() -> Self

Returns the "default value" for a type. Read more