ilusm.dev

set

List-backed sets for small collections - create an empty set, add an element (no-op if already present), remove an element, compute the union, intersection, and difference of two sets, and test membership.

Load with: use set

What this module does

set implements mathematical sets as plain ilusm lists with linear-scan deduplication. Because membership checks are O(n), this module is intended for small collections where simplicity matters more than raw throughput. All operations return new lists - sets are immutable values.

Quick example

use set

a = setne()           # empty set
a = setad(a, "x")
a = setad(a, "y")
a = setad(a, "x")     # no-op (already in set)
prn(a)                # ["x", "y"]

a = setrm(a, "x")     # ["y"]

b = setad(setne(), "y")
b = setad(b, "z")

prn(setun(a, b))      # ["y", "z"]  (union)
prn(setin(a, b))      # ["y"]       (intersection)
prn(setdf(a, b))      # []          (difference: in a but not b)

prn(setmb(b, "z"))    # tru

Functions

Set operations

setne()

Returns an empty set (empty list).

setad(s, x)

Returns s with x added. If x is already a member, returns s unchanged.

setrm(s, x)

Returns s with all occurrences of x removed.

setun(a, b)

Returns the union of sets a and b - all elements from both, deduplicated.

setin(a, b)

Returns the intersection - elements that appear in both a and b.

setdf(a, b)

Returns the set difference - elements in a that are not in b.

setmb(s, x)

Returns tru if x is a member of s.

Notes

  • Membership checks are O(n) linear scans - use for small sets only.
  • Requires trl.