Crates.io | aph_disjoint_set |
lib.rs | aph_disjoint_set |
version | 0.1.1 |
source | src |
created_at | 2023-06-17 16:14:21.39935 |
updated_at | 2023-06-17 16:40:57.575961 |
description | Disjoint set implementation with optimized memory usage and ability to detach elements. |
homepage | |
repository | https://foss.heptapod.net/angelicos_phosphoros/aph-disjoint-set |
max_upload_size | |
id | 893006 |
size | 140,340 |
Implementation of Disjoint Set structure, also known as Union-Find.
DisjointSet
is suitable for cases when you know amount of nodes ahead of time,DisjointSetArrayU8
/DisjointSetArrayU16
/DisjointSetArrayU32
/DisjointSetArrayU64
, for cases
when it is preferable to store all datastructure inline without extra heap allocation.DisjointSetDynamic
if exact number of nodes isn't known beforehand.DisjointSet
and DisjointSetDynamic
use smaller node tag type to reduce memory usage.
It is significant, for example, DisjointSet
with u16::MAX
nodes use 256 KByte memory,
which fits to L2 caches pretty well, while u16::MAX+1
would use approximately 512 KBytes,
which is much harder to fit.
This optimization is opaque to user so there is no need to think about it.I benchmarked againts most popular crates with union find implementation on crates.io: union-find and ena. Benchmarked on Core i5 6300HQ.
Labyrinth/aph-disjoint-set serial time: [230.91 µs 231.54 µs 232.21 µs]
Labyrinth/aph-disjoint-set parallel time: [84.909 µs 85.978 µs 87.173 µs]
Labyrinth/Crate Union-Find time: [254.05 µs 254.21 µs 254.37 µs]
Labyrinth/Crate eno time: [444.44 µs 444.77 µs 445.11 µs]
Islands/aph-disjoint-set serial time: [177.12 µs 183.31 µs 190.54 µs]
Islands/aph-disjoint-set parallel time: [132.87 µs 134.11 µs 135.66 µs]
Islands/Crate Union-Find time: [167.80 µs 172.37 µs 177.84 µs]
Islands/Crate eno time: [399.41 µs 400.37 µs 401.52 µs]
Benchmarks code available by link.
Crate is licensed by either Apache 2.0 or MIT license so by contributing to it you agree to license your code by both licenses.