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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

disjoint_set-0.9.0.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

disjoint_set-0.9.0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file disjoint_set-0.9.0.tar.gz.

File metadata

  • Download URL: disjoint_set-0.9.0.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for disjoint_set-0.9.0.tar.gz
Algorithm Hash digest
SHA256 f9640f906824d6c3bf5f92597616245112b953125d73f60490d49124ba731585
MD5 380fa578652b1e5fd6895415ac19bdf6
BLAKE2b-256 3ba36eed6a39991aaef974ae8d917aa9cc201c8f56844ab0f0dfeb319cd63f25

See more details on using hashes here.

File details

Details for the file disjoint_set-0.9.0-py3-none-any.whl.

File metadata

  • Download URL: disjoint_set-0.9.0-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for disjoint_set-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 58378ee8d474355f07bca1c0633803e01259abd6e02cc3d49a9799aa203457ea
MD5 bd58337a08427693b825212a09b1876f
BLAKE2b-256 e4c6bd8bdd42d4b8b473890cba9cbd69f941c4b29d91a1e4cdcdb05ebb41da9f

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.9.0 This release

2 files

0.8.0

2 files

0.7.4

2 files

0.7.3

2 files

0.7.2

2 files

0.7.1

2 files

0.7.0

2 files

0.6.3

2 files

0.6.2

2 files

0.6.1

2 files

0.6.0

2 files

0.5.0

2 files

0.4.0

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page