disjoint-hash-set

Crates.iodisjoint-hash-set
lib.rsdisjoint-hash-set
version1.0.0
sourcesrc
created_at2022-06-16 08:16:51.017796
updated_at2022-06-16 08:16:51.017796
descriptionA disjoint set / union-find data structure suitable for incremental tracking of connected component identified by their hash.
homepage
repositoryhttps://github.com/znrm/disjoint-hash-set
max_upload_size
id607311
size16,344
Zaniar Moradian (znrm)

documentation

README

disjoint-hash-set

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);

Commit count: 16

cargo fmt