Set: Purely Functional Sets
by Dave Herman (dherman at ccs dot neu dot edu)
This library provides two implementations of functional sets
backed by hash tables: one comparing elements for equality using
equal?, the other using eq?.
The data structures of this library are immutable. They are
implemented on top of PLT Scheme’s immutable hash tables, and
therefore should have O(1) running time for extending and
O(log n) running time for lookup.
This library was inspired by
SRFI-1
and GHC’s
Data.Set library.
1 Getting started
The easiest way to use this library is to install its main module,
which exports all bindings in the two individual modules:
2 Sets using equal?
Determines whether x is a set.
Produces a set containing the elements in
ls.
If
ls contains duplicates (as determined by
equal?),
the resulting set contains only the rightmost of the duplicate elements.
Produces a list containing the elements in s.
No guarantees are made about the order of the elements in the list.
An empty set.
Determines whether s is empty.
Produces the set intersection of sets.
Produces the left-associative set difference of sets.
Produces the set union of sets.
Produces the exclusive union of sets.
This operation is associative and extends to the n-ary case
by producing a set of elements that appear in an odd number of
sets.
Equivalent to
but implemented more efficiently.
Note that this is not necessarily the same thing as
Produces a set containing the elements of s and elts.
Produces a set containing x and the elements of s.
Determines whether the set s contains the element x.
Produces the number of elements in s.
(for/set (for-clause ...) body ...+) |
|
|
Like
for/list and
for*/list, respectively,
but the result is a set. The expressions in the
body forms
must produce a single value, which is included in the resulting set.
Produces a sequence that iterates over the elements of s.
Sets themselves have the prop:sequence property and can therefore
be used as sequences.
Determines whether
s1 and
s2 contain exactly the same elements,
using
equal? to compare elements.
Determines whether all elements of
s1 are contained in
s2
(i.e., whether
s1 is an improper subset of
s2),
using
equal? to compare elements.
3 Sets using eq?
Determines whether x is a set.
Produces a set containing the elements in
ls.
If
ls contains duplicates (as determined by
eq?),
the resulting set contains only the rightmost of the duplicate elements.
Produces a list containing the elements in s.
No guarantees are made about the order of the elements in the list.
An empty set.
Determines whether s is empty.
Produces the set intersection of sets.
Produces the left-associative set difference of sets.
Produces the set union of sets.
Produces the exclusive union of sets.
This operation is associative and extends to the n-ary case
by producing a set of elements that appear in an odd number of
sets.
Equivalent to
but implemented more efficiently.
Note that this is not necessarily the same thing as
Produces a set containing the elements of s and elts.
Produces a set containing x and the elements of s.
Determines whether the set s contains the element x.
Produces the number of elements in s.
Like
for/list and
for*/list, respectively,
but the result is a set. The expressions in the
body forms
must produce a single value, which is included in the resulting set.
Produces a sequence that iterates over the elements of s.
Sets themselves have the prop:sequence property and can therefore
be used as sequences.
Determines whether
s1 and
s2 contain exactly the same elements,
using
eq? to compare elements.
Determines whether all elements of
s1 are contained in
s2
(i.e., whether
s1 is an improper subset of
s2),
using
eq? to compare elements.