simple UnionFind model with test on element is inside. How to use, see jupyter book in https://github.com/BastiYourDeveloper/clustering-closest-pairs
Project description
unionfind-link
With this UnionFind library you will get a basic library for checking:
- Is this element in same set like another element?
- joining elements together in one set
Currently there is no rank implemented, so the tree structure is simple. Only a reverse tree structure is supported. Meaning, for printing the elements in the set, it goes through all elements to test the set.
Nor the less it is a good start for answering the mentioned question and joining sets.
Have Fun! Basti
# - test linking
uf = UnionFind()
uf.union(1, 2)
uf.union(3, 4)
uf.union(5, 6)
uf.union(1, 3)
uf.union(6, 4)
assert uf.connected(1, 6)
# = test with None
root = uf.find(7)
try:
uf.union(7, 8)
except:
uf.add(7)
assert not uf.connected(7,8)
uf.union(7,8)
assert uf.connected(7,8)
# = test without None
uf.findOrCreate(9)
uf.union(9,10)
assert uf.connected(9,10)
Example Application
A realy good application for unionfind structures is clustering with closest-pairs. See: https://github.com/BastiYourDeveloper/clustering-closest-pairs
Enjoy the UnionFind structure with methods like findOrCreate() and find(). Method find() can be used to test if element is already in UnionFind structure, and returns None if not.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file unionfind_link-1.0.0.tar.gz.
File metadata
- Download URL: unionfind_link-1.0.0.tar.gz
- Upload date:
- Size: 12.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a30318c84c3bb0313673c1c67563b0292a13e00a6fca2af4f09b8918e007434a
|
|
| MD5 |
a7ff19000e2f1a8b3498a0d3e716bc48
|
|
| BLAKE2b-256 |
9035a8ea500c565f884bfa01b6c69d2fe3cb41e66f56b208bcd52ac98ce0c9d2
|
File details
Details for the file unionfind_link-1.0.0-py3-none-any.whl.
File metadata
- Download URL: unionfind_link-1.0.0-py3-none-any.whl
- Upload date:
- Size: 12.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
496ba46ca9fc79101bff94995669b198e5c8f927ffad056721af8f943aeefcaa
|
|
| MD5 |
5bcb7e34435e03408f3c9df772945506
|
|
| BLAKE2b-256 |
46eade6ffd8797ca404c5939e0a32e41088833b015f317e2fc1830fe346b53ed
|