Packages / rupm

rs-collections-union-find 0.1.0

Disjoint-set union with path compression, union by rank and component counts

Install

cargo add rs-collections-union-find --registry rupm

In Ruststudio: Packages, search for rs-collections-union-find, Install.

Owner: Rust Studio. Licence: MIT OR Apache-2.0. Total downloads: 0. Published 2026-11-23.

Versions

README

# rs-collections-union-find

Disjoint-set union (union-find) over `0..n` with path compression and union by rank. It tracks the number of components and the size of each set, can list the groups, and never panics on out-of-range indices.

## Install

Add it with `rupm add rs-collections-union-find` (or `cargo add rs-collections-union-find --registry rupm`).

## Usage

```rust
use rs_collections_union_find::UnionFind;

let mut uf = UnionFind::new(5);
uf.union(0, 1);
uf.union(1, 2);
assert!(uf.connected(0, 2));
assert_eq!(uf.components(), 3);
assert_eq!(uf.set_size(0), Some(3));
```

## API overview

- `UnionFind::new(n)`, `add()`, `len()`, `is_empty()`
- `find(x) -> Option<usize>`, `union(a, b) -> bool`, `connected(a, b) -> bool`
- `components()`, `set_size(x)`, `groups()`