(** Purely functional set, implemented as a red, black tree. *)
typeset
(** The empty set. *)
valempty:set
(** Inserts a new element into the set. Runs in O(log(n)). *)
valinsert:member->set->set
(** Determines if a specific value is a member of the set. Runs in O(log(n)). *)
valmember:member->set->bool
(** Computes the union of two sets. Runs in O(mlog(n)), for the first set is of length m and the second is of length n. Hence if the lengths of the sets are known, this algorithm is most efficient if the second set is the longer one. *)
valunion:set->set->set
(** Creates a set from a list. Will deduplicate if necessary. Runs in O(log(n!)). *)
valof_list:memberlist->set
(** Removes the element specified from the set, if it exists. *)
valremove:member->set->set
(** Calculates the first set, without any elements that appear in the second. *)
valdifference:set->set->set
(** Calculates the number of elements in the set. Note this is not tail recursive. Runs in O(n). *)
valcardinality:set->int
end
moduletypeSetSpecification=sig
(** Type of members in the set. *)
typemember
(** Comparison should return a value less than 0 for when the first value is smaller, greater than 0 for when the second is smaller, and 0 when they are equivalent. *)