UFx is a pure python library that implements the disjoint-set data structure which allows the union-find operations.
Two implementations are proposed.
uf_hash using python dictionary
uf_tree using nodes linked each to its ansestror
Those implementations are design for hashable types. However it is possible to use the UFNode class present in the uf_tree implementation with non-hashable types (see the API documentation part below).
UFx was only tested with python 2.7, python 3.5 and pypy but may work with other versions python virtual machines.
Performances
The uf_hash implementation is the recommanded one. It performs well with the classic python virtual machine. The uf_tree implementation is really slow due to the poor performances of python with pointer like based data structures. The use of another python virtual machine like pypy its recommanded when using the uf_tree implementation.
TODO: Table of computation speed and memory consumption
API documentation
Import
You can import one of the implementation of the disjoint-set data structure
from ufx import uf_tree as ufx
or
from ufx import uf_hash as ufx
Quick Example
import sys
import random
uf = ufx.UnionFind()
az = "abcdefghijklmnopqrstuvwxyz"
az += az.upper()
for e in az:
uf.make_set(e)
i = 0
while i < 26:
i += 1
uf.union(random.choice(az), random.choice(az))
print(uf)
print(uf.get_size('a'))
uf.clear()
print(uf)
Hashable types
TODO
Non-hashable types
Look on the class UFNode
Release files for UFx 1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| UFx-1.0.0.tar.gz | 4.6 kB | Details |
Release files / UFx-1.0.0.tar.gz
| Download URL | UFx-1.0.0.tar.gz |
|---|---|
| Size | 4.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
94b9d11dbe6847fb6994c768e5259f7b625cfcdd016e09dbcff1aac89a75be51
|
|
BLAKE2b-256 checksum How to use checksums |
4b333cabcd51f4f9ec345cfc9667a8638a7df86d3c11a2ac5ee9643830698c1a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |