Disjoint set data structure implementation for Python
Project description
disjoint-set
DisjointSet (a.k.a. union–find data structure or merge–find set) implementation for Python.
Prerequisites
The only requirement is having Python 3 installed, you can verify this by running:
$ python --version
Python 3.7.2
Installation
pip install disjoint-set
You can verify he package was installed to your current environment by running:
$ pip list | grep disjoint-set
disjoint-set 0.5.0
Usage
>>> from disjoint_set import DisjointSet
>>> ds = DisjointSet()
>>> ds.find(1)
1
>>> ds.union(1,2)
>>> ds.find(1)
2
>>> ds.find(2)
2
>>> ds.connected(1,2)
True
>>> ds.connected(1,3)
False
>>> "a" in ds
False
>>> ds.find("a")
'a'
>>> "a" in ds
True
>>> list(self.dset)
[(1, 2), (2, 2), (3, 3), ('a', 'a')]
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
Project details
Release history Release notifications | RSS feed
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.5.0.tar.gz
(2.9 kB
view hashes)
Built Distribution
Close
Hashes for disjoint_set-0.5.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25d216c55ee7dd03140559260fa0d31e438514fd224a68e7c73c4cb1ba437b52 |
|
MD5 | 08ed7868bd0cb665d4f2549877b8c828 |
|
BLAKE2b-256 | 5c893157f3efdd1bd4f8e20b6f6ee0daff88ea222dc982e7dd2b235c308f3e05 |