No matching definitions.

tur/set

stdlib/set.tur

typed Set[A]: persistent set backed by the HAMT.

Since: Phase TC2-C

defstruct

Set

(defstruct Set [A])

parameterized persistent set with element type A.

Since: Phase TC2

defn

set-new

(set-new [A])

create a new empty Set[A].

An empty Set[A].

(set-new)  ; => empty Set

Since: Phase TC2

defn

set-add-eq-o

(set-add-eq-o [A])

============================================================================

defn

set-has-eq-o?

(set-has-eq-o? [A])

raw membership test: explicit hash, boxed carrier element.

defn

set-del-eq-o

(set-del-eq-o [A])

raw removal: explicit hash, boxed carrier element.

defmacro

set-add

(set-add [s h x])

add element x to the set; returns a new set.

sSet[A]
hprecomputed hash of x (from Hash[A] typeclass)
xelement 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)

defmacro

set-remove

(set-remove [s h x])

remove element x from the set; returns a new set.

sSet[A]
hprecomputed hash of x
xelement to remove (type A)

A new Set[A] without x.

(set-remove my-set (hash 42) 42)  ; => set without 42

Since: Phase TC2

defmacro

set-member?

(set-member? [s h x])

check whether element x is in the set.

sSet[A]
hprecomputed hash of x
xelement to test (type A)

true if x is in the set, false otherwise.

(set-member? my-set (hash 42) 42)  ; => true

Since: Phase TC2

defn

set-count

(set-count [A])

return the number of elements in the set.

sSet[A]

Integer count of elements.

(set-count my-set)  ; => 3

Since: Phase TC2

defn

set-union

(set-union [A])

compute the union of two sets.

afirst Set[A]
bsecond Set[A]

A new Set[A] containing all elements from both sets.

(set-union set-a set-b)  ; => union set

Since: Phase TC2

defn

set-intersect

(set-intersect [A])

compute the intersection of two sets.

afirst Set[A]
bsecond 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

defn

set-diff

(set-diff [A])

compute set difference a \ b (elements in a but not b).

aSet[A] (base set)
bSet[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

defn

set-eq?

(set-eq? [a : int b : int])

compare two sets for equality.

afirst Set[A]
bsecond Set[A]

true if both sets contain exactly the same elements.

(set-eq? set-a set-b)  ; => true

Since: Phase TC2

defn

set-eq-cmp?

(set-eq-cmp? [a : int b : int ^fat cmp-fn])

structural equality with a user-supplied element

aSet[A]
bSet[A]
cmp-fncomparator 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)

defn

set-free

(set-free [A])

free the Set wrapper struct.

sSet[A] to free
(set-free my-set)

Since: Phase TC2

defn

set-hamt

(set-hamt [A])

internal accessor returning the backing HAMT pointer.

defn

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.

iterhamt/iter-alloc-allocated handle scanning s1
s2-hamtraw HAMT pointer of the second set (from set-hamt)
keyeqstamped 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

defn

set-eq-driver

(set-eq-driver [A])

allocate the iter box, run set-eq-loop, free.

Since: Phase TCO-Eq-MapSet

defn

set-eq-full

(set-eq-full [A])

membership equality using the HAMT structure.

definstance

Eq[Set]

(definstance Eq [Set])
defmacro

set-add1

(set-add1 [s x])

insert one element, computing its hash via Hash[A].

defmacro

set-add-each__

(set-add-each__ [s & xs])

internal helper for the set-of macro.

defn

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

defmacro

set-of

(set-of [& xs])