Disjoint set / union find
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.
Source Distribution
disjoint_union-0.2.0.tar.gz
(2.8 kB
view hashes)
Built Distribution
Close
Hashes for disjoint_union-0.2.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48a4e18316adeb3000cb44860d98d9ad9f61e6c2dc033c2f1e01c3708504ea1f |
|
MD5 | 01c119d4df8b7224f698d8bf68c1425c |
|
BLAKE2b-256 | 05482cd637e486e3e30668404d3f620cfb35ca432e1c876f45665a140a9fedc3 |