tur/set
typed Set[A]: persistent set backed by the HAMT.
Since: Phase TC2-C
Set
(defstruct Set [A])
parameterized persistent set with element type A.
Since: Phase TC2
set-new
(set-new)
create a new empty Set[A].
An empty Set[A].
(set-new) ; => empty Set
Since: Phase TC2
set-add
(set-add [s :int h :int x :int])
add element x to the set; returns a new set.
| s | Set[A] | |
| h | precomputed hash of x (from Hash[A] typeclass) | |
| x | element to add (type A) |
A new Set[A] containing x.
(set-add my-set (hash 42) 42) ; => set with 42
Since: Phase TC2
set-remove
(set-remove [s :int h :int x :int])
remove element x from the set; returns a new set.
| s | Set[A] | |
| h | precomputed hash of x | |
| x | element to remove (type A) |
A new Set[A] without x.
(set-remove my-set (hash 42) 42) ; => set without 42
Since: Phase TC2
set-member?
(set-member? [s :int h :int x :int])
check whether element x is in the set.
| s | Set[A] | |
| h | precomputed hash of x | |
| x | element to test (type A) |
true if x is in the set, false otherwise.
(set-member? my-set (hash 42) 42) ; => true
Since: Phase TC2
set-count
(set-count [s :int])
return the number of elements in the set.
| s | Set[A] |
Integer count of elements.
(set-count my-set) ; => 3
Since: Phase TC2
set-union
(set-union [a :int b :int])
compute the union of two sets.
| a | first Set[A] | |
| b | second Set[A] |
A new Set[A] containing all elements from both sets.
(set-union set-a set-b) ; => union set
Since: Phase TC2
set-intersect
(set-intersect [a :int b :int])
compute the intersection of two sets.
| a | first Set[A] | |
| b | second Set[A] |
A new Set[A] containing only elements present in both a and b.
(set-intersect set-a set-b) ; => intersection set
Since: Phase TC2
set-diff
(set-diff [a :int b :int])
compute set difference a \ b (elements in a but not b).
| a | Set[A] (base set) | |
| b | Set[A] (elements to remove) |
A new Set[A] with elements of a that are not in b.
(set-diff set-a set-b) ; => difference set
Since: Phase TC2
set-eq?
(set-eq? [a :int b :int])
compare two sets for equality.
| a | first Set[A] | |
| b | second Set[A] |
true if both sets contain exactly the same elements.
(set-eq? set-a set-b) ; => true
Since: Phase TC2
set-eq-cmp?
(set-eq-cmp? [a :int b :int cmp-fn])
structural equality with a user-supplied element
| a | Set[A] | |
| b | Set[A] | |
| cmp-fn | comparator fn [a :int b :int] :bool applied to element pairs |
true iff both sets have the same count and every element of `a` has at least one structurally-equal counterpart in `b` per cmp-fn.
Since: Phase F3-5 (cross-plan-followups)
set-free
(set-free [s :int])
free the Set wrapper struct.
| s | Set[A] to free |
(set-free my-set)
Since: Phase TC2
Eq[Set]
(definstance Eq [Set])
membership equality using the HAMT structure.