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: December 2018

Summary of exported operations:

empty :: Ord a => RedBlackTree a   
Return an empty set.
null :: RedBlackTree a -> Bool   
Test for an empty set.
elem :: Ord a => a -> RedBlackTree a -> Bool   
Returns true if an element is contained in a set.
insert :: Ord a => a -> RedBlackTree a -> RedBlackTree a   
Inserts an element into a set if it is not already there.
delete :: Ord a => 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 :: Ord a => [a] -> RedBlackTree a   
Transforms a list of elements into a set.
union :: Ord a => RedBlackTree a -> RedBlackTree a -> RedBlackTree a   
Computes the union of two sets.
intersect :: Ord a => RedBlackTree a -> RedBlackTree a -> RedBlackTree a   
Computes the intersection of two sets.
disjoint :: Ord a => RedBlackTree a -> RedBlackTree a -> Bool   
Test for disjointness of sets.

Exported datatypes:


Set

Type synonym: Set a = RedBlackTree a


Exported operations:

empty :: Ord a => RedBlackTree a   

Return an empty set.

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

null :: RedBlackTree a -> Bool   

Test for an empty set.

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

elem :: Ord a => 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 :: Ord a => a -> RedBlackTree a -> RedBlackTree a   

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

delete :: Ord a => 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 :: Ord a => [a] -> RedBlackTree a   

Transforms a list of elements into a set.

union :: Ord a => RedBlackTree a -> RedBlackTree a -> RedBlackTree a   

Computes the union of two sets.

intersect :: Ord a => RedBlackTree a -> RedBlackTree a -> RedBlackTree a   

Computes the intersection of two sets.

disjoint :: Ord a => RedBlackTree a -> RedBlackTree a -> Bool   

Test for disjointness of sets.