Struct disjoint_sets::UnionFind
[−]
[src]
pub struct UnionFind<Element: ElementType = usize> { /* fields omitted */ }
Array-based union-find representing a set of disjoint sets.
Methods
impl<Element: ElementType> UnionFind<Element>
[src]
fn new(size: usize) -> Self
Creates a new union-find of size
elements.
Panics
If size
elements would overflow the element type Element
.
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) -> Element
Creates a new element in a singleton set.
Panics
If allocating another element would overflow the element type
Element
.
fn union(&mut self, a: Element, b: Element) -> 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: Element) -> Element
Finds the representative element for the given element’s set.
fn equiv(&self, a: Element, b: Element) -> 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<Element>
Returns a vector of set representatives.
Trait Implementations
impl<Element: Clone + ElementType> Clone for UnionFind<Element>
[src]
fn clone(&self) -> UnionFind<Element>
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