| Crates.io | indices_union_find |
| lib.rs | indices_union_find |
| version | 0.1.1 |
| created_at | 2025-07-18 07:57:17.180494+00 |
| updated_at | 2025-07-29 06:19:33.123738+00 |
| description | An efficient and minimal union-find (disjoint-set) implementation over generic unsigned index types. |
| homepage | |
| repository | https://github.com/enjuichang123/indices_union_find.git |
| max_upload_size | |
| id | 1758715 |
| size | 50,168 |
indices_union_findAn efficient and minimal union-find (disjoint-set) implementation over generic unsigned index types.
This crate provides a UnionFind<T> structure for managing partitions (disjoint sets) of indices. It supports union by size and path compression, enabling nearly-constant-time operations. The index type T can be any unsigned integer that implements the UnsignedIndex trait (e.g., u8, u16, u32, etc.).
The core data structure, UnionFind
parent: Vec
size: Vec
These optimizations ensure that find and union operations remain efficient, even for large sets of indices.
The companion structure, Partition
/// An ordered set of boundary nodes defining alternating interval membership.
///
/// Each interval [aᵢ, aᵢ₊₁) is considered filled if i is even,
/// and empty if i is odd.
///
/// The boundaries must be strictly ordered and deduplicated; any
/// overlapping or unordered input must be resolved during construction.
pub boundaries: BTreeSet
Functions are provided to construct a Partition
BTreeSet
HashSet
keys of BTreeMap<T, _> or HashMap<T, _>
The conversion process groups neighboring indices into compact intervals, reducing memory usage and avoiding redundant storage. Even in the worst case, where filled intervals alternate with empty ones, the number of stored boundaries is at most the number of input indices plus one.
This design is motivated by the common degeneracy in index-value mappings, where many indices may share the same value. In such cases, grouping indices into equivalence classes allows logical operations to be applied once per class rather than redundantly for each index.
This project is licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you shall be licensed as above, without any additional terms or conditions.