LispPad
Search
K

(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

set-type-tag
Symbol representing the set type. The type-for procedure of library (lispkit type) returns this symbol for all set objects.
(make-eq-set)
Create a new empty set using eq? as equivalence function.
(make-eqv-set)
Create a new empty set using eqv? as equivalence function.
(make-equal-set)
Create a new empty set using equal? as equivalence function.
(make-set hash equiv)
(make-set hash equiv k)
Create a new empty set using the given hash function hash and equivalence function equiv. An initial capacity k can be provided optionally.
(eq-set element ...)
Create a new set using eq? as equivalence function. Initialize it with the values element ... .
(eqv-set element ...)
Create a new set using eqv? as equivalence function. Initialize it with the values element ... .
(equal-set element ...)
Create a new set using equal? as equivalence function. Initialize it with the values element ... .

Inspection

(set-equivalence-function s)
Returns the equivalence function used by set s.
(set-hash-function s)
Returns the hash function used by set s.
(set-mutable? s)
Returns #t if set s is mutable.

Predicates

(set? obj)
Returns #t if obj is a set.
(set-empty? obj)
Returns #t if obj is an empty set.
(set=? s1 s2)
Returns #t if set s1 and set s2 are using the same equivalence function and contain the same elements.
(disjoint? s1 s2)
Returns #t if set s1 and set s2 are disjoint sets.
(subset? s1 s2)
Returns #t if set s1 is a subset of set s2.
(proper-subset? s1 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.
(set-contains? s element)
Returns # if set s contains element.
(set-any? s proc)
Returns true if there is at least one element in set s for which procedure proc returns true (i.e. not #f).
(set-every? s proc)
Returns true if procedure proc returns true (i.e. not #f) for all elements of set s.

Procedures

(set-size s)
Returns the number of elements in set s.
(set-elements s)
Returns the elements of set s as a vector.
(set-copy s)
(set-copy s mutable)
Copies set s creating an immutable copy if mutable is set to #f or if mutable is not provided.
(set-for-each s proc)
Applies procedure proc to all elements of set s in an undefined order.
(set-filter s pred)
Creates a new set containing the elements of set s for which the procedure pred returns true.
(set-union s s1 ...)
Creates a new set containing the union of s with s1 ....
(set-intersection s s1 ...)
Creates a new set containing the intersection of s with s1 ....
(set-difference s s1 ...)
Creates a new set containing the difference of s and the sets in s1 ... .
(set->list s)
Returns the elements of set s as a list.
(list->eq-set elements)
Creates a new set using the equivalence function eq? from the values in list elements.
(list->eqv-set elements)
Creates a new set using the equivalence function eqv? from the values in list elements.
(list->equal-set elements)
Creates a new set using the equivalence function equal? from the values in list elements.

Mutators

(set-adjoin! s element ...)
Adds element ... to the set s.
(set-delete! s element ...)
Deletes element ... from the set s.
(set-clear! s)
(set-clear! s k)
Clears set s and reserves a capacity of k elements if k is provided.
(list->set! s elements)
Adds the values of list elements to set s.
(set-filter! s pred)
Removes all elements from set s for which procedure pred returns #f.
(set-union! s s1 ...)
Stores the union of set s and sets s1 ... in s.
(set-intersection! s s1 ...)
Stores the intersection of set s and the sets s1 ... in s.
(set-difference! s s1 ...)
Stores the difference of set s and the sets s1 ... in s.