union_find
Implementations of the disjoint-set forest data structure that supports the union-find algorithm.
This crate focuses on ease of use and simplicity.
Background / Context
Getting Started
Specify union-find-rs
as a dependency in your Cargo.toml
.
[]
= "^0.2"
- add the following to the top of your
.rs
file-
use *;
-
- see the trait
UnionFind
for the core operations of union-find - see the struct
DisjointSets
for an implementation ofUnionFind
Example
use HashSet;
use *;
let mut sets: = new;
sets.make_set.unwrap;
sets.make_set.unwrap;
sets.make_set.unwrap;
sets.union.unwrap;
// the disjoint sets as a vector of vectors
let as_vec: = sets.into_iter.collect;
// there should be 2 disjoint sets, where one of them only contains `9` and the other one
// only contains `1` and `4`
assert_eq!;
assert!;
assert!;