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 [A])
create a new empty Set[A].
An empty Set[A].
(set-new) ; => empty Set
Since: Phase TC2
set-add-eq-o
(set-add-eq-o [A])
============================================================================
set-has-eq-o?
(set-has-eq-o? [A])
raw membership test: explicit hash, boxed carrier element.
set-del-eq-o
(set-del-eq-o [A])
raw removal: explicit hash, boxed carrier element.
set-add
(set-add [s h x])
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 (element retyped :int -> :A, content-keyed: set-element-api-generalization)
set-remove
(set-remove [s h x])
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 h x])
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 [A])
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])
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])
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])
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 ^fat 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 [A])
free the Set wrapper struct.
| s | Set[A] to free |
(set-free my-set)
Since: Phase TC2
set-hamt
(set-hamt [A])
internal accessor returning the backing HAMT pointer.
set-eq-loop
(set-eq-loop [iter ptr<void> s2-hamt ptr<void> keyeq ptr<void>] :)
pure-Turmeric structural-equality walk over s1's HAMT.
| iter | hamt/iter-alloc-allocated handle scanning s1 | |
| s2-hamt | raw HAMT pointer of the second set (from set-hamt) | |
| keyeq | stamped key comparator (from hamt/keyeq on s1's hamt) |
true iff every entry of s1 is present in s2 under keyeq.
Since: Phase TCO-Eq-MapSet
set-eq-driver
(set-eq-driver [A])
allocate the iter box, run set-eq-loop, free.
Since: Phase TCO-Eq-MapSet
set-eq-full
(set-eq-full [A])
membership equality using the HAMT structure.
Eq[Set]
(definstance Eq [Set])
set-add1
(set-add1 [s x])
insert one element, computing its hash via Hash[A].
set-add-each__
(set-add-each__ [s & xs])
internal helper for the set-of macro.
set-empty-for
(set-empty-for [^Hash A ^MapKey A])
variadic Set literal.
| & xs -- zero or more elements of a single type A. Each element is used | ||
| as its own hash (identity-hash), matching the typed Set[A] | ||
| convention; scalar element types (int, etc.) dedupe by value. |
A fresh Set[A] containing xs; duplicate elements collapse to one. Note: this is the lowering target of the #set{...} data literal (-Xdata-literals). Writing #set{1 2 3} is preferred over calling set-of directly.
(set-of) ; => empty Set
(set-of 1 2 3) ; => Set {1, 2, 3}
(set-of 1 1 2) ; => Set {1, 2}
Since: set-element-api-generalization
set-of
(set-of [& xs])