Module btreeset
SourceDescription
BTreeSet — ordered set of unique elements keyed by (Ord elem elem).
BTreeSet elem is a newtype over (Vec elem) — runtime layout matches Vec, but dispatch treats it as a nominally distinct type.
Methods currently panic at runtime; real bodies require host intrinsics for ordered insert, range walk, and O(log n) lookup. Range operations surface as eager (Vec elem) today and narrow to lazy sequences once the Seq hierarchy is wired. Set-algebra methods (.union, .intersection, .difference, …) live on a dedicated BTreeSetOps trait until (Foldable Self) (Filterable Self) prerequisites land and the standard Set impl applies. Cursor / CursorMut are deferred.
Not re-exported by the prelude — use :use :open silo:std.collections.btreeset ....
Data Types
Types
- BTreeSet
Ordered set of unique elements.
Functions
Functions
- btreeset-from-hashset
Convert a
(HashSet elem)to a(BTreeSet elem).- btreeset-from-vec
Convert a
(Vec elem)to a(BTreeSet elem).
Trait Implementations
impl BTreeSet for ?610302
.contains ( elem (BTreeSet elem) → Bool )
.contains ( elem (BTreeSet elem) → Bool )
.contains — true iff the element is in the set. Real body: linear scan over the backing Vec with structural equality (same tactic as hashset-contains). Argument order matches HashSet.contains (elem Self -> Bool) rather than the original stub's inverted order. Real O(log n) balanced-tree lookup arrives with the tree runtime.
.difference ( (BTreeSet elem) (BTreeSet elem) → (BTreeSet elem) )
.difference ( (BTreeSet elem) (BTreeSet elem) → (BTreeSet elem) )
.difference — elements in the first set but not the second. First set is deeper on the stack, second is on top.
.first ( (BTreeSet elem) → (Option elem) )
.first ( (BTreeSet elem) → (Option elem) )
.first returns Some with the smallest element or None if empty. O(log n).
.insert ( elem (BTreeSet elem) → (BTreeSet elem) Bool )
.insert ( elem (BTreeSet elem) → (BTreeSet elem) Bool )
.insert adds an element, returning the updated set and a Bool indicating whether the element was newly added (true = new, false = already present). O(log n). (Ord elem elem) constraint is implicit on the dispatch once the real body lands.
.intersection ( (BTreeSet elem) (BTreeSet elem) → (BTreeSet elem) )
.intersection ( (BTreeSet elem) (BTreeSet elem) → (BTreeSet elem) )
.intersection — elements in both sets, deduplicated. Iteration order follows the first set (matches std BTreeSet::intersection). Real O(min(n,m) * log(max(n,m))) arrives with the tree runtime.
.is-disjoint ( (BTreeSet elem) (BTreeSet elem) → Bool )
.is-disjoint ( (BTreeSet elem) (BTreeSet elem) → Bool )
.is-disjoint — true iff the two sets share no elements. Two empty sets are considered disjoint.
.is-subset ( (BTreeSet elem) (BTreeSet elem) → Bool )
.is-subset ( (BTreeSet elem) (BTreeSet elem) → Bool )
.is-subset — true iff every element of the first set (deeper) is also in the second. The empty set is a subset of every set; every set is a subset of itself.
.is-superset ( (BTreeSet elem) (BTreeSet elem) → Bool )
.is-superset ( (BTreeSet elem) (BTreeSet elem) → Bool )
.is-superset — swap-argument dual of .is-subset.
.last ( (BTreeSet elem) → (Option elem) )
.last ( (BTreeSet elem) → (Option elem) )
.last returns Some with the largest element or None if empty. O(log n).
.range ( elem..elem (BTreeSet elem) → (Vec elem) )
.range ( elem..elem (BTreeSet elem) → (Vec elem) )
.range — elements in the half-open interval [start, end) in ascending order. O(log n + k) where k is the number of elements yielded. Spec specifies (Seq elem _) but Seq is a trait alias; the stub returns (Vec elem) until a shared lazy-sequence concrete type exists.
.range-from ( elem.. (BTreeSet elem) → (Vec elem) )
.range-from ( elem.. (BTreeSet elem) → (Vec elem) )
.range-from — elements >= start in ascending order. O(log n + k). Returns (Vec elem) per the range stub caveat.
.range-to ( ..elem (BTreeSet elem) → (Vec elem) )
.range-to ( ..elem (BTreeSet elem) → (Vec elem) )
.range-to — elements < end in ascending order. O(log n + k). Returns (Vec elem) per the range stub caveat.
.remove ( elem (BTreeSet elem) → (BTreeSet elem) Bool )
.remove ( elem (BTreeSet elem) → (BTreeSet elem) Bool )
.remove deletes an element, returning the updated set and a Bool indicating whether the element was previously present. O(log n).
.retain ( [elem → Bool ] (BTreeSet elem) → (BTreeSet elem) )
.retain ( [elem → Bool ] (BTreeSet elem) → (BTreeSet elem) )
.retain — keep elements for which the predicate returns true. Returns a new BTreeSet containing only the retained elements.
.symmetric-difference ( (BTreeSet elem) (BTreeSet elem) → (BTreeSet elem) )
.symmetric-difference ( (BTreeSet elem) (BTreeSet elem) → (BTreeSet elem) )
.symmetric-difference — elements in exactly one of the two sets. First-set-only elements surface before second-set-only elements (matches std iteration order).
.to-vec ( (BTreeSet elem) → (Vec elem) )
.to-vec ( (BTreeSet elem) → (Vec elem) )
.to-vec — produce a (Vec elem) with the same elements. Runtime identity cast — the backing cell is already a Vec. Spec mandates ascending-order iteration once the balanced tree maintains it; until then elements surface in insertion order. Callers MUST NOT depend on ordering yet.
.union ( (BTreeSet elem) (BTreeSet elem) → (BTreeSet elem) )
.union ( (BTreeSet elem) (BTreeSet elem) → (BTreeSet elem) )
.union — all elements in either set, deduplicated. Real body: linear-scan concatenation via values_equal (same tactic as btreeset-contains). Result preserves the BTreeSet uniqueness invariant. Real O(n + m) via balanced-tree merge arrives with the tree runtime. Iteration order is insertion-order for now (first set's elements, then second set's new elements).