Disjoint set / union find algorithm
Project description
Disjoint Union
Implementation of the union find algorithm. This library will work with any hashable objects.
Installation
PyPI
python3 -m pip install disjoint_union
Usage
DisjointUnion
is a subclass of list
and can be instantiated by passing it an iterable. You can use the pipe methods |
& |=
as well as the union(x, y)
and unions(*iterable)
methods.
In [1]: from disjoint_union import DisjointUnion In [2]: s = DisjointUnion(range(3)) In [3]: s Out[3]: [{0, 1, 2}] In [5]: s.unions(range(6, 10)) Out[5]: [{0, 1, 2}, {6, 7, 8, 9}] In [6]: s.union(2, 5) Out[6]: [{0, 1, 2, 5}, {6, 7, 8, 9}] In [7]: s.union(5, 6) Out[7]: [{0, 1, 2, 5, 6, 7, 8, 9}] In [8]: s | range(10, 15) Out[8]: [{0, 1, 2, 5, 6, 7, 8, 9}, {10, 11, 12, 13, 14}] In [9]: s | (9, 10, 15) Out[9]: [{0, 1, 2, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}]
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.
Filename, size | File type | Python version | Upload date | Hashes |
---|---|---|---|---|
Filename, size disjoint_union-0.3.0-py2.py3-none-any.whl (3.3 kB) | File type Wheel | Python version py2.py3 | Upload date | Hashes View |
Filename, size disjoint_union-0.3.0.tar.gz (2.9 kB) | File type Source | Python version None | Upload date | Hashes View |
Close
Hashes for disjoint_union-0.3.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd8950282000502fd42d8d2d783b27328b01198a062bae87a230cc4f1c5a1dc1 |
|
MD5 | 2b10bc9ab6e2b8020de859ad2299b893 |
|
BLAKE2-256 | ef41159e5f7050af8458b26bb3bd512d50c2762837758526d087ec1d6c838b74 |