## A.16 library( ordsets ): Ordered Set Manipulation

Ordered sets are lists with unique elements sorted to the standard order of terms (see sort/2). Exploiting ordering, many of the set operations can be expressed in order N rather than N^2 when dealing with unordered sets that may contain duplicates. The `library(ordsets)` is available in a number of Prolog implementations. Our predicates are designed to be compatible with common practice in the Prolog community. The implementation is incomplete and relies partly on `library(oset)`, an older ordered set library distributed with SWI-Prolog. New applications are advices to use `library(ordsets)`.

Some of these predicates match directly to corresponding list operations. It is adviced to use the versions from this library to make clear you are operating on ordered sets.

ord_empty(?Set)
  True if Set is an empty ordered set. Set unifies with the empty list.
list_to_ord_set(+List, -OrdSet)
  Convert a List to an ordered set. Same as sort/2.
ord_add_element(+Set, +Element, -NewSet)
  Add an element to an ordered set. NewSet is the same as Set if Element is already part of Set.
ord_del_element(+Set, +Element, -NewSet)
  Delete Element from Set. Succeeds without changing Set if Set does not contain Element.
ord_intersect(+Set1, +Set2)
  True if the intersection of Set1 and Set2 is non-empty.
ord_intersection(+Set1, +Set2, -Intersection)
  True if Intersection is the intersection of Set1 and Set2.
ord_disjoint(+Set1, +Set2)
  True if Set1 and Set2 have no common element. Negation of ord_intersect/2.
ord_subtract(+Set, +Delete, -Remaining)
  True if Remaining contains the elements of Set that are not in set Delete.
ord_union(+Set1, +Set2, -Union)
  True if Union contains all elements from Set1 and Set2
ord_union(+Set1, +Set2, -Union, -New)
  Defined as if `ord_union(Set1, Set2, Union)`, `ord_subtract(Set2, Set1, New)`.
ord_subset(+Sub, +Super)
  True if all elements of Sub are in Super.
ord_memberchk(+Element, +Set)
  True if Element appears in Set. Does not backtrack. Same as memberchk/2.