Note that the implementation is generally left-biased. Functions that take
two sets as arguments and combine them, such as union and intersection,
prefer the entries in the first argument to those in the second. Of course,
this bias can only be observed when equality is an equivalence relation
instead of structural equality.

These modules are intended to be imported qualified, to avoid name
clashes with Prelude functions, e.g.

import Data.Set (Set)
import qualified Data.Set as Set

Warning

The size of the set must not exceed maxBound::Int. Violation of
this condition is not detected and if the size limit is exceeded, its
behaviour is undefined.

Implementation

The implementation of Set is based on size balanced binary trees (or
trees of bounded balance) as described by:

Note: if p is not actually antitone, then spanAntitone will split the set
at some unspecified point where the predicate switches from holding to not
holding (where the predicate is seen to hold before the first element and to fail
after the last element).

O(1). Decompose a set into pieces based on the structure of the underlying
tree. This function is useful for consuming a set in parallel.

No guarantee is made as to the sizes of the pieces; an internal, but
deterministic process determines this. However, it is guaranteed that the pieces
returned will be in ascending order (all elements in the first subset less than all
elements in the second, and so on).

O(log n). Return the index of an element, which is its zero-based
index in the sorted sequence of elements. The index is a number from 0 up
to, but not including, the size of the set. Calls error when the element
is not a member of the set.

O(log n). Retrieve an element by its index, i.e. by its zero-based
index in the sorted sequence of elements. If the index is out of range (less
than zero, greater or equal to size of the set), error is called.

O(log n). Delete the element at index, i.e. by its zero-based index in
the sorted sequence of elements. If the index is out of range (less than zero,
greater or equal to size of the set), error is called.

O(n). The expression (showTreeWith hang wide map) shows
the tree that implements the set. If hang is
True, a hanging tree is shown otherwise a rotated tree is shown. If
wide is True, an extra wide version is shown.