UFx
===

UFx is a pure python library that implements the `disjoint-set data
structure <https://en.wikipedia.org/wiki/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``
