Data.DisjointSet.Int

Description

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.

Synopsis

# Documentation

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.

Constructors

 DisjointIntSet (Vector Int) (Vector Int) Int Int

Instances

 Source # MethodsshowList :: [DisjointIntSet] -> ShowS #

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.

Finds the representative set for that element.

Gives how many elements in this element's set.

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

How many distinct sets.

How many elements in this disjoint set.

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.