Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

UFx is a pure python library that implements the disjoint-set data structure which allows the union-find operations.

Project Description

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.


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


You can import one of the implementation of the disjoint-set data structure

from ufx import uf_tree as ufx


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:
i = 0
while i < 26:
    i += 1
    uf.union(random.choice(az), random.choice(az))

Hashable types


Non-hashable types

Look on the class UFNode

Release History

Release History

This version
History Node


Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
UFx-1.0.0.tar.gz (4.6 kB) Copy SHA256 Checksum SHA256 Source Jun 15, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting