disjoint-set-stateful- Monadic disjoint set

Safe HaskellNone



This module contains non-monadic functions for querying disjoint int sets. See Data.DisjointSet.Int.Monadic for information about how to create and modify disjoint int sets.

There are two other disjoint int set packages on hackage, namely:

  • "disjoint-set"
  • "disjoint-sets-st"

The first is a pure disjoint int set implementation, so as it doesn't do in place array updates in ST it will presumably be somewhat slower, with the data structure used likely taking more space and having log(n) access speed.

This package does not include a pure implementation, you're better off using "disjoint-set" for that.

"disjoint-sets-st" does offer an implementation in IO, however, it's missing two features:

1) The ability to "freeze" a disjoint set, and then query it in a pure way. 2) Maintaining a circular linked list of each set so one can quickly discover all the elements of one set without quering through the entire structure.

This package implements both of the above features.



data DisjointIntSet Source #

This is the non-monadic disjoint int set. It can be created by using the monadic operations and then calling freeze, unsafeFreeze or runDisjointIntSet as appropriate.

Alternatively create can create a disjoint set directly from any Foldable structure of int pairs, e.g. and [(Int, Int)].

There's not a variable and fixed length version of this because well, you can't modify the non-monadic version anyway.

create :: Foldable t => t (Int, Int) -> DisjointIntSet Source #

create creates a DisjointIntSet from a list of int pairs, or indeed any Foldable structure of (Int, Int).

It basically calls union for each of the pairs and freezes the result. Use this when you've got a list of pairs for your disjoint set and you have no need to extend it later.

find :: DisjointIntSet -> Int -> Int Source #

Finds the representative set for that element.

count :: DisjointIntSet -> Int -> Int Source #

Gives how many elements in this element's set.

findAndCount :: DisjointIntSet -> Int -> (Int, Int) Source #

Both find and count, but in one operation, so in theory faster than running them separately.

numSets :: DisjointIntSet -> Int Source #

How many distinct sets.

size :: DisjointIntSet -> Int Source #

How many elements in this disjoint set.

nextInSet :: DisjointIntSet -> Int -> Int Source #

Gets the next element in the current set. This is a circular list, so if you iterate on this you'll get back to the element you started with in the end.

setToList :: DisjointIntSet -> Int -> [Int] Source #

Returns a list of the elements in the selected set.