Skip to content

Transform

matchlab.core.dsu

Functions to transform data between tabular and graph structures.

Classes:

  • DisjointSet

    Disjoint set forest with "path compression" and "union by rank" heuristics.

DisjointSet

DisjointSet()

Bases: Generic[T]


              flowchart TD
              matchlab.core.dsu.DisjointSet[DisjointSet]

              

              click matchlab.core.dsu.DisjointSet href "" "matchlab.core.dsu.DisjointSet"
            

Disjoint set forest with "path compression" and "union by rank" heuristics.

This follows implementation from Cormen, Thomas H., et al. Introduction to algorithms. MIT press, 2022

Initialise the disjoint set.

Methods:

  • add

    Add a new element to the disjoint set.

  • union

    Merge the sets containing elements x and y.

  • get_components

    Return the connected components of the disjoint set.

Attributes:

parent instance-attribute

parent: dict[T, T] = {}

rank instance-attribute

rank: dict[T, int] = {}

add

add(x: T) -> None

Add a new element to the disjoint set.

union

union(x: T, y: T) -> None

Merge the sets containing elements x and y.

get_components

get_components() -> list[set[T]]

Return the connected components of the disjoint set.