YAP 7.1.0
Ordered Sets

The following ordered set manipulation routines are available once included with the use_module(library(ordsets)) command. More...

Detailed Description

The following ordered set manipulation routines are available once included with the use_module(library(ordsets)) command.

An ordered set is represented by a list having unique and ordered elements Output arguments are guaranteed to be ordered sets, if the relevant inputs are This is a slightly patched version of Richard O'Keefe's original library

In this module, sets are represented by ordered lists with no duplicates Thus {c,r,a,f,t} would be [a,c,f,r,t] The ordering is defined by the < family of term comparison predicates, which is the ordering used by sort/2 and setof/3

The benefit of the ordered representation is that the elementary set operations can be done in time proportional to the Sum of the argument sizes rather than their Product Some of the unordered set routines, such as member/2 , length/2 , select/3 can be used unchanged The main difficulty with the ordered representation is remembering to use it!


Class Documentation

◆ ord_add_element/3

class ord_add_element/3

ord_add_element(+ Set1, + Element, ? Set2)

Inserting Element in Set1 returns Set2 It should give exactly the same result as merge(Set1, [Element], Set2), but a bit faster, and certainly more clearly The same as ord_insert/3

◆ ord_del_element/3

class ord_del_element/3

ord_del_element(+ Set1, + Element, ? Set2)

Removing Element from Set1 returns Set2

◆ ord_disjoint/2

class ord_disjoint/2

ord_disjoint(+ Set1, + Set2)

Holds when the two ordered sets have no element in common

◆ ord_insert/3

class ord_insert/3

ord_insert(+ Set1, + Element, ? Set2)

Inserting Element in Set1 returns Set2 It should give exactly the same result as merge(Set1, [Element], Set2), but a bit faster, and certainly more clearly The same as ord_add_element/3

◆ ord_intersect/2

class ord_intersect/2

ord_intersect(+ Set1, + Set2)

ord_intersect(+Set1, +Set2)

Holds when the two ordered sets have at least one element in common

is true when the two ordered sets have at least one element in common Note that the test is == rather than =

◆ ord_intersection/3

class ord_intersection/3

ord_intersection(+ Set1, + Set2, ? Intersection)

ord_intersection(+Set1, +Set2, ?Intersection)

Holds when Intersection is the ordered representation of Set1 and Set2

is true when Intersection is the ordered representation of Set1 and Set2, provided that Set1 and Set2 are ordered sets

◆ ord_intersection/4

class ord_intersection/4

ord_intersection(+ Set1, + Set2, ? Intersection, ? Diff)

ord_intersection(+Set1, +Set2, ?Intersection, ?Difference)

Holds when Intersection is the ordered representation of Set1 and Set2 Diff is the difference between Set2 and Set1

is true when Intersection is the ordered representation of Set1 and Set2, provided that Set1 and Set2 are ordered sets

◆ ord_member/2

class ord_member/2

ord_member(+ Element, + Set)

Holds when Element is a member of Set

◆ ord_seteq/2

class ord_seteq/2

ord_seteq(+ Set1, + Set2)

Holds when the two arguments represent the same set

◆ ord_setproduct/3

class ord_setproduct/3

ord_setproduct(+ Set1, + Set2, - Set)

ord_setproduct(+Set1, +Set2, ?Product)

If Set1 and Set2 are ordered sets, Product will be an ordered set of x1-x2 pairs

is in fact identical to setproduct(Set1, Set2, Product) If Set1 and Set2 are ordered sets, Product will be an ordered set of x1-x2 pairs Note that we cannot solve for Set1 and Set2, because there are infinitely many solutions when Product is empty, and may be a large number in other cases

◆ ord_subset/2

class ord_subset/2

ord_subset(+ Set1, + Set2)

Holds when every element of the ordered set Set1 appears in the ordered set Set2

◆ ord_subtract/3

class ord_subtract/3

ord_subtract(+ Set1, + Set2, ? Difference)

Holds when Difference contains all and only the elements of Set1 which are not also in Set2

◆ ord_symdiff/3

class ord_symdiff/3

ord_symdiff(+ Set1, + Set2, ? Difference)

ord_symdiff(+Set1, +Set2, ?Difference)

Holds when Difference is the symmetric difference of Set1 and Set2

is true when Difference is the symmetric difference of Set1 and Set2

◆ ord_union/3

class ord_union/3

ord_union(+ Set1, + Set2, ? Union)

Holds when Union is the union of Set1 and Set2

◆ ord_union/4

class ord_union/4

ord_union(+ Set1, + Set2, ? Union, ? Diff)

ord_union(+Set1, +Set2, ?Union, ?Difference)

Holds when Union is the union of Set1 and Set2 and Diff is the difference

is true when Union is the union of Set1 and Set2 and Difference is the difference between Set2 and Set1

◆ ord_union/2

class ord_union/2

ord_union(+ Sets, ? Union)

Holds when Union is the union of the lists Sets

◆ list_to_ord_set/2

class list_to_ord_set/2

list_to_ord_set(+List, ?Set)

is true when Set is the ordered representation of the set represented by the unordered representation List The only reason for giving it a name at all is that you may not have realised that sort/2 could be used this way