Disjoint set / union find
Project description
disjoint_set
union find / disjoint union set
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.1.tar.gz
(2.8 kB
view hashes)
Built Distribution
Close
Hashes for disjoint_union-0.0.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | efcd0957c5b99c702246cea7dd3ab7d20f23a1ddbdbe17ae73530ee2fd721ca2 |
|
MD5 | b97f7b79c9c54b48081da54ffd387d28 |
|
BLAKE2b-256 | 43473872b35b13f57475ac6140bad9b59be94aea4d383c1fbd0d13a3bb1599f7 |