(lispkit set)

Library (lispkit set) provides a generic implementation for sets of objects. Its API design is compatible to the R6RS-style API of library (lispkit hashtable).

A set is a data structure for representing collections of objects. Any object can be used as element, provided a hash function and a suitable equivalence function is available. A hash function is a procedure that maps elements to exact integer objects. It is the programmer’s responsibility to ensure that the hash function is compatible with the equivalence function, which is a procedure that accepts two objects and returns true if they are equivalent and #f otherwise. Standard sets for arbitrary objects based on the eq?, eqv?, and equal? predicates are provided.

Constructors

Symbol representing the set type. The type-for procedure of library (lispkit type) returns this symbol for all set objects.

Create a new empty set using eq? as equivalence function.

Create a new empty set using eqv? as equivalence function.

Create a new empty set using equal? as equivalence function.

Create a new empty set using the given hash function hash and equivalence function equiv. An initial capacity k can be provided optionally.

Create a new set using eq? as equivalence function. Initialize it with the values element ... .

Create a new set using eqv? as equivalence function. Initialize it with the values element ... .

Create a new set using equal? as equivalence function. Initialize it with the values element ... .

Inspection

Returns the equivalence function used by set s.

Returns the hash function used by set s.

Returns #t if set s is mutable.

Predicates

Returns #t if obj is a set.

Returns #t if obj is an empty set.

Returns #t if set s1 and set s2 are using the same equivalence function and contain the same elements.

Returns #t if set s1 and set s2 are disjoint sets.

Returns #t if set s1 is a subset of set s2.

Returns #t if set s1 is a proper subset of set s2, i.e. s1 is a subset of s2 and s1 is not equivalent to s2.

Returns # if set s contains element.

Returns true if there is at least one element in set s for which procedure proc returns true (i.e. not #f).

Returns true if procedure proc returns true (i.e. not #f) for all elements of set s.

Procedures

Returns the number of elements in set s.

Returns the elements of set s as a vector.

Copies set s creating an immutable copy if mutable is set to #f or if mutable is not provided.

Applies procedure proc to all elements of set s in an undefined order.

Creates a new set containing the elements of set s for which the procedure pred returns true.

Creates a new set containing the union of s with s1 ....

Creates a new set containing the intersection of s with s1 ....

Creates a new set containing the difference of s and the sets in s1 ... .

Returns the elements of set s as a list.

Creates a new set using the equivalence function eq? from the values in list elements.

Creates a new set using the equivalence function eqv? from the values in list elements.

Creates a new set using the equivalence function equal? from the values in list elements.

Mutators

Adds element ... to the set s.

Deletes element ... from the set s.

Clears set s and reserves a capacity of k elements if k is provided.

Adds the values of list elements to set s.

Removes all elements from set s for which procedure pred returns #f.

Stores the union of set s and sets s1 ... in s.

Stores the intersection of set s and the sets s1 ... in s.

Stores the difference of set s and the sets s1 ... in s.

Last updated