Registry / data / disjoint-set

disjoint-set

JSON →
library0.9.0pypypi✓ verified 86d ago

A Python implementation of the disjoint set (union-find) data structure, featuring path compression and union by rank/size. Current version 0.9.0, requires Python >=3.10. The library is stable with occasional updates.

pip install disjoint-set
INSTALL
IMPORT
SIG · DISJOINT-SET
D
disjoint-set
datapythonv0.9.0
Install
1.5s avg
Import
22ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.9.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.024s · 18.1MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.020s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

DisjointSet
from disjoint_set import DisjointSet

Quickstart: create a DisjointSet, use union and find.

from disjoint_set import DisjointSet ds = DisjointSet() ds.find(1) # returns 1 ds.union(1, 2) ds.find(2) # returns 1 (or 2, depending on implementation) print(ds.connected(1, 2)) # True print(len(ds)) # 1 (number of disjoint sets)
Debug
Known issues
gotchaThe library does not support initializing with a set of elements; elements are added implicitly on find/union. If you need to pre-populate, call find on each element first.
fix
Explicitly call 'ds.find(x)' for each element before unions, or use 'ds.add(x)' if available (not in this library).
affects: all
gotchaThe library uses path compression and union by size, but the implementation may not guarantee O(alpha(n)) amortized if used incorrectly. Ensure you always call union with two elements (creates if missing).
fix
Always call find after union to compress paths immediately for subsequent operations.
affects: all
Errors
Common errors & fixes
ImportError: cannot import name 'DisjointSet' from 'disjoint_set'
Incorrect import path or library not installed.
fix
Install using 'pip install disjoint-set' and import as 'from disjoint_set import DisjointSet'.
TypeError: DisjointSet() takes no arguments
Trying to pass initial elements to the constructor, which is not supported.
fix
Instantiate without arguments: ds = DisjointSet(); then add elements via find/union.
AttributeError: 'DisjointSet' object has no attribute 'add'
Attempting to use a non-existent method 'add'. This library does not have an explicit add method.
fix
Use 'find' to implicitly add an element: ds.find(x).
Upgrade
Version history
0.9.0latest on PyPI · released Feb 21, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
8
OpenAI (training)
1
Resources
disjoint-set — pip install disjoint-set · libregistry