Disjoint set / union find
Project description
Disjoint Union
Implementation of the union find algorithm.
Installation
PyPI
python3 -m pip install disjoint_union
Usage
In [1]: from disjoint_union import DisjointUnion
In [2]: a, b, c, d, e, f, g = {1,2,3}, {4,5,6}, {'a', 'b', 0}, None, ValueError(), (object, str), str
In [3]: s = DisjointUnion(a)
In [4]: s
Out[4]: [{1, 2, 3}]
In [5]: s.unions(b).unions(c).union(d, d)
Out[5]: [{1, 2, 3}, {4, 5, 6}, {'b', 0, 'a'}, {None}]
In [6]: s.unions('test', 22, 55, 99)
Out[6]: [{1, 2, 3}, {4, 5, 6}, {'b', 0, 'a'}, {None}, {99, 'test', 22, 55}]
In [7]: s.union(22, 77)
Out[7]: [{1, 2, 3}, {4, 5, 6}, {'b', 0, 'a'}, {None}, {99, 'test', 77, 22, 55}]
In [8]: s + 66
Out[8]: [{1, 2, 3}, {4, 5, 6}, {'b', 0, 'a'}, {None}, {99, 'test', 77, 22, 55}, {66}]
In [9]: s.union(66, 22)
Out[9]: [{1, 2, 3}, {4, 5, 6}, {'b', 0, 'a'}, {None}, {22, 55, 66, 77, 99, 'test'}]
In [11]: s |= f
In [12]: s
Out[12]:
[{1, 2, 3},
{4, 5, 6},
{'b', 0, 'a'},
{None},
{22, 55, 66, 77, 99, 'test'},
{builtins.object, builtins.str}]
In [13]: ('!@#$' + (s + g) + 'hey there') | ( {22,44} | set('char set'))
Out[13]:
[{1, 2, 3}, {4, 5, 6}, {0, 66, 99, 'h', 77, 'e', 'a', 'test', 44, ' ', 'c', 'b', 22, 55, 't', 's', 'r'}, {None}, {<class 'object'>, <class 'str'>}, {'!@#$'}, {'hey there'}]
In [14]: s.unions(1, 4, 22, None, 's', str)
Out[14]:
[{'b', 1, 2, 3, 4, 5, 6, 'c', ' ', 'h', None, 77, 'r', 's', 'a', 66, 't', 'test', 22, 0, 99, <class 'object'>, 'e', 44, <class 'str'>, 55}, {'!@#$'}, {'hey there'}]
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.0.4.tar.gz
(2.9 kB
view hashes)
Built Distribution
Close
Hashes for disjoint_union-0.0.4-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eeded2bb10987274f807da350bf3545310ca2b482eba7af9f76ce9e65d0530cf |
|
MD5 | bdc04188db5de59ef23ebaecf3e73884 |
|
BLAKE2b-256 | 2c6c0221e59be596a585dddc96710c48465310101ae2b810a7e2471768729b17 |