set/intersection
Intersection of two sets (stable insertion order)
Usage
I:=set/intersection(A, B)Equivalent shorthand with mathematical operator:
I:=A∩BDescription
Computes the intersection of two sets A and B, returning only the elements
that appear in both inputs.
The implementation wraps a Rust IndexSet intersection iterator, so the result
preserves stable insertion order:
Elements are returned in the order they appear in A, limited to those also in B.
Input
Arguments:
A : set of T (or array treated as a set; duplicates ignored)
B : set of T (or array treated as a set; duplicates ignored)
Element type constraints:
T must be hashable and comparable for equality (Eq + Hash in Rust).
Common scalar kinds: integers, strings, symbols, booleans.
Output
Result:
I : set of T containing only elements common to both A and B.
Examples
Simple intersection
Numbers
Order follows the first set
Details
Set semantics:
Inputs are coerced to sets by dropping duplicates.
Only distinct elements present in both A and B are returned.
Stable insertion order:
Matches Rust IndexSet behavior: intersection elements follow A’s order.
Performance:
Average O(|A| + |B|) time with hashing, memory O(|A|) for the result.
Determinism:
Output is deterministic across runs and platforms.
Errors
Incorrect number of arguments (expects two).
Unsupported element type (not hashable or not comparable).
Inconsistent element kinds between A and B.