toy-lib-0.1.0.0
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.UnionFind.Mutable

Description

A union-Find tree or a disjoint set.

Typical problems

Synopsis

Documentation

newtype MUnionFind s #

Dense, mutable Union-Find tree (originally by `@pel`)

>>> stree <- newMUF 3
>>> sameMUF stree 0 2
False
>>> unifyMUF stree 0 2
True
>>> sameMUF stree 0 2
True
>>> unifyMUF stree 0 2
False

See also

https://algo-method.com/descriptions/132

Constructors

MUnionFind (MVector s MUFNode) 

data MUFNode #

MUFChild parent | MUFRoot size.

Constructors

MUFChild !Int 
MUFRoot !Int 

Instances

Instances details
Show MUFNode # 
Instance details

Defined in Data.UnionFind.Mutable

Eq MUFNode # 
Instance details

Defined in Data.UnionFind.Mutable

Methods

(==) :: MUFNode -> MUFNode -> Bool #

(/=) :: MUFNode -> MUFNode -> Bool #

Unbox MUFNode # 
Instance details

Defined in Data.UnionFind.Mutable

Vector Vector MUFNode # 
Instance details

Defined in Data.UnionFind.Mutable

MVector MVector MUFNode # 
Instance details

Defined in Data.UnionFind.Mutable

IsoUnbox MUFNode (Bool, Int) # 
Instance details

Defined in Data.UnionFind.Mutable

Methods

toURepr :: MUFNode -> (Bool, Int) #

fromURepr :: (Bool, Int) -> MUFNode #

newtype Vector MUFNode # 
Instance details

Defined in Data.UnionFind.Mutable

newtype MVector s MUFNode # 
Instance details

Defined in Data.UnionFind.Mutable

newMUF :: PrimMonad m => Int -> m (MUnionFind (PrimState m)) #

\(O(N)\) Creates a new Union-Find tree of the given size.

rootMUF :: (HasCallStack, PrimMonad m) => MUnionFind (PrimState m) -> Int -> m Int #

\(O(\alpha(N))\) Returns the root node index.

sameMUF :: (HasCallStack, PrimMonad m) => MUnionFind (PrimState m) -> Int -> Int -> m Bool #

\(O(\alpha(N))\) Checks if the two nodes are under the same root.

_unwrapMUFRoot :: MUFNode -> Int #

Just an internal helper.

unifyMUF :: (HasCallStack, PrimMonad m) => MUnionFind (PrimState m) -> Int -> Int -> m Bool #

\(O(1)\) Unifies two nodes. Returns True when thry're newly unified.

unifyMUF_ :: (HasCallStack, PrimMonad m) => MUnionFind (PrimState m) -> Int -> Int -> m () #

\(O(1)\)

sizeMUF :: (HasCallStack, PrimMonad m) => MUnionFind (PrimState m) -> Int -> m Int #

\(O(\alpha(N))\) Returns the size of the a node, starting with `1`.

clearMUF :: PrimMonad m => MUnionFind (PrimState m) -> m () #

\(O(N)\)

groupRootsMUF :: (HasCallStack, PrimMonad m) => MUnionFind (PrimState m) -> m (Vector Int) #

\(O(N \alpha(N))\) Returns all root vertices.

groupsMUF :: (HasCallStack, PrimMonad m) => MUnionFind (PrimState m) -> m (IntMap [Int]) #

\(O(N W)\) Collects groups. Returns a list of (root, component). Too slow?