disjoint-set
DisjointSet (a.k.a. union–find data structure or merge–find set) implementation for Python.
Prerequisites
The only requirement is using Python 3.10+. You can verify this by running:
$ python --version
Python 3.10.18
Installation
pip install disjoint-set
You can verify you're running the latest package version by running:
>>> import disjoint_set
>>> disjoint_set.__version__
'0.9.0'
Usage
Import & instantiate
>>> from disjoint_set import DisjointSet
>>> DisjointSet()
DisjointSet({})
>>> DisjointSet({1: 1})
DisjointSet({1: 1})
>>> DisjointSet.from_iterable([1,2,3])
DisjointSet({1: 1, 2: 2, 3: 3})
Perform find & union operations
>>> ds = DisjointSet()
>>> ds.find(1)
1
>>> ds.union(1,2)
>>> ds.find(1)
2
>>> ds.find(2)
2
Check if values belong to the same set
>>> ds = DisjointSet({1: 2, 2: 2, 3: 3})
>>> ds.connected(1,2)
True
>>> ds.connected(1,3)
False
Check if values are present within the data structure
>>> ds = DisjointSet()
>>> "a" in ds
False
>>> ds.find("a")
'a'
>>> "a" in ds
True
List elements and sets within the disjoint set
>>> ds = DisjointSet({1: 2, 2: 2, 3: 3})
>>> list(ds)
[(1, 2), (2, 2), (3, 3)]
>>> ds = DisjointSet({1: 2, 2: 2, 3: 3})
>>> list(ds.itersets())
[{1, 2}, {3}]
Contributing
Feel free to open any issues on github.
Authors
License
This project is licensed under the MIT License - see the LICENSE.md file for details
Release files for disjoint-set 0.9.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| disjoint_set-0.9.0.tar.gz | 3.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| disjoint_set-0.9.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.3 kB
Release files / disjoint_set-0.9.0.tar.gz
| Download URL | disjoint_set-0.9.0.tar.gz |
|---|---|
| Size | 3.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f9640f906824d6c3bf5f92597616245112b953125d73f60490d49124ba731585
|
|
BLAKE2b-256 checksum How to use checksums |
3ba36eed6a39991aaef974ae8d917aa9cc201c8f56844ab0f0dfeb319cd63f25
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / disjoint_set-0.9.0-py3-none-any.whl
| Download URL | disjoint_set-0.9.0-py3-none-any.whl |
|---|---|
| Size | 4.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
58378ee8d474355f07bca1c0633803e01259abd6e02cc3d49a9799aa203457ea
|
|
BLAKE2b-256 checksum How to use checksums |
e4c6bd8bdd42d4b8b473890cba9cbd69f941c4b29d91a1e4cdcdb05ebb41da9f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|