Struct disjoint_sets::UnionFind
[−]
[src]
pub struct UnionFind<Element: ElementType = usize> { /* fields omitted */ }
Vector-based union-find representing a set of disjoint sets.
Methods
impl<Element: ElementType> UnionFind<Element>
[src]
pub fn new(size: usize) -> Self
[src]
Creates a new union-find of size
elements.
Panics
If size
elements would overflow the element type Element
.
pub fn len(&self) -> usize
[src]
The number of elements in all the sets.
pub fn is_empty(&self) -> bool
[src]
Is the union-find devoid of elements?
It is possible to create an empty UnionFind
and then add
elements with alloc
.
pub fn alloc(&mut self) -> Element
[src]
Creates a new element in a singleton set.
Panics
If allocating another element would overflow the element type
Element
.
pub fn union(&mut self, a: Element, b: Element) -> bool
[src]
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
.
pub fn find(&self, element: Element) -> Element
[src]
Finds the representative element for the given element’s set.
pub fn equiv(&self, a: Element, b: Element) -> bool
[src]
Determines whether two elements are in the same set.
pub fn force(&self)
[src]
Forces all laziness, so that each element points directly to its set’s representative.
pub fn to_vec(&self) -> Vec<Element>
[src]
Returns a vector of set representatives.
Trait Implementations
impl<Element: Clone + ElementType> Clone for UnionFind<Element>
[src]
fn clone(&self) -> UnionFind<Element>
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<Element: Debug + ElementType> Debug for UnionFind<Element>
[src]
fn fmt(&self, formatter: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more