Crates.io | disjoint-hash-set |
lib.rs | disjoint-hash-set |
version | 1.0.0 |
source | src |
created_at | 2022-06-16 08:16:51.017796 |
updated_at | 2022-06-16 08:16:51.017796 |
description | A disjoint set / union-find data structure suitable for incremental tracking of connected component identified by their hash. |
homepage | |
repository | https://github.com/znrm/disjoint-hash-set |
max_upload_size | |
id | 607311 |
size | 16,344 |
A Rust implementation of a disjoint set / union-find data structure for incremental tracking of connected components identified by their hash.
Incorporates rank-based set joins and path compression to ensure the asymptotically optimal time complexity associated with union-find algorithms.
use disjoint_hash_set::DisjointHashSet;
let mut djhs = DisjointHashSet::new();
djhs.link("hello", "hi");
djhs.link("hello", "👋");
assert!(djhs.is_linked("hi", "👋"));
// `DisjointHashSet` can be built from an iterator of edges
let djhs = vec![("a", "b"), ("a", "c"), ("d", "e"), ("f", "f")]
.into_iter()
.collect::<DisjointHashSet<_>>();
// Consume djhs to iterate over each disjoint set
let sets = djhs.sets(); // looks like [{"a", "b", "c"}, {"d", "e"}, {"f"}]
assert_eq!(sets.count(), 3);