Skip to main content

disjoint-set

PyPI - Python Version PyPI Coveralls PyPI - License

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)

Source distribution for disjoint-set 0.9.0
File Size Uploaded
disjoint_set-0.9.0.tar.gz 3.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for disjoint-set 0.9.0
File Interpreter ABI Platform
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}

Release history Release notifications | RSS feed

This release

0.9.0 This release

2 release files

0.8.0

2 release files

0.7.4

2 release files

0.7.3

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.3

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page