Module Set

Library for a set datatype with an implementation using red-black trees. This module is intended to be used qualified, i.e.,

import qualified Set import Set (Set)

All the operations are based on the primitive ordering on elements obtained by (==) and (<).

Author: Björn Peemöller

Version: September 2015

Summary of exported operations:

empty :: RedBlackTree a   
Return an empty set.
null :: RedBlackTree a -> Bool   
Test for an empty set.
elem :: a -> RedBlackTree a -> Bool   
Returns true if an element is contained in a set.
insert :: a -> RedBlackTree a -> RedBlackTree a   
Inserts an element into a set if it is not already there.
delete :: a -> RedBlackTree a -> RedBlackTree a   
Delete an element from a set.
toList :: RedBlackTree a -> [a]   
Transforms a set into an ordered list of its elements.
fromList :: [a] -> RedBlackTree a   
Transforms a list of elements into a set.
union :: RedBlackTree a -> RedBlackTree a -> RedBlackTree a   
Computes the union of two sets.
intersect :: RedBlackTree a -> RedBlackTree a -> RedBlackTree a   
Computes the intersection of two sets.
disjoint :: RedBlackTree a -> RedBlackTree a -> Bool   
Test for disjointness of sets.

Exported datatypes:


Set

Type synonym: Set a = RedBlackTree a


Exported operations:

empty :: RedBlackTree a   

Return an empty set.

null :: RedBlackTree a -> Bool   

Test for an empty set.

Further infos:
  • solution complete, i.e., able to compute all solutions

elem :: a -> RedBlackTree a -> Bool   

Returns true if an element is contained in a set.

Example call:
(elem e s)
Parameters:
  • e : an element to be checked for containment
  • s : a set
Returns:
True iff e is contained in s

insert :: a -> RedBlackTree a -> RedBlackTree a   

Inserts an element into a set if it is not already there.

delete :: a -> RedBlackTree a -> RedBlackTree a   

Delete an element from a set.

toList :: RedBlackTree a -> [a]   

Transforms a set into an ordered list of its elements.

Further infos:
  • solution complete, i.e., able to compute all solutions

fromList :: [a] -> RedBlackTree a   

Transforms a list of elements into a set.

union :: RedBlackTree a -> RedBlackTree a -> RedBlackTree a   

Computes the union of two sets.

intersect :: RedBlackTree a -> RedBlackTree a -> RedBlackTree a   

Computes the intersection of two sets.

disjoint :: RedBlackTree a -> RedBlackTree a -> Bool   

Test for disjointness of sets.