A haskell
implementation of union-find data structure based on ST Monad.
It mainly follows this union-find repository. More specifically, the src/Data/UnionFind/ST.hs
file in it.
However, I do have some modifications:
- the
Root a
constructor inChain s a
datatype does not depend ons
state, while inunion-find
repository, the related data typeLink s a
has constructorInfo {-# UNPACK #-} !(STRef s (Info a))
whereSTRef s
is actually not necessary. - I create
StEq
typelcass witheq
function to handle the equality check (==
symbol) ofPoint
andChain
datatype, this is because they are always in anST s
monad and the normal(==)
function does not fit in this type signature. Inunion-find
repository, such a treatment does not exist, and it has resulted in a weird bug(as I believe).
run cabal test
It will run test/Main.hs
for testing