Skip to main content

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


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)

Uploaded Source

Built Distribution

disjoint_union-0.0.4-py2.py3-none-any.whl (3.2 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page