haccepted-0.1.0.0: Data structures and algorithms
Safe HaskellNone
LanguageHaskell2010

DSU

Description

Disjoint set union

Data structure to maintain disjoint sets of Ints, supporting find and union. Uses union by size and path halving.

Sources:

Use unboxed arrays (IOUArray/STUArray) for best performance! n = r - l + 1 in all instances below. α is the inverse Ackermann function.

Synopsis

Documentation

newD :: MArray a Int m => (Int, Int) -> m (a Int Int) Source #

Creates a new DSU structure with elements in the range (l, r), each in its own set. O(n).

sameSetD :: MArray a Int m => a Int Int -> Int -> Int -> m Bool Source #

Returns whether the two elements are in the same set. Amortized O(α(n)).

unionD :: MArray a Int m => a Int Int -> Int -> Int -> m Bool Source #

Unites the sets containing the two elements. If they are already in the same set, returns False, otherwise performs the union and returns True. Amortized O(α(n)).