Home / Docs / Standard library / Built-in methods

add

Release v0.4.0Edition 0.5 preview

A built-in method, resolved by the type of its receiver (spec/14 §2). Edition 0.5 preview.

una
edit s.add(item: T) -> Unit
  where s: Set[T]
edit s.add(item: T) -> Unit
  where s: HashSet[T]
edit b.add(item: Int) -> Unit
  where b: BitSet

Updates s in place, written edit s.add(...): afterwards s.has(item: x), and s.len grows by one when the item was not there. O(log n) (spec/28 §6); on a HashSet, O(|k|) expected, amortized (spec/28 §7). On a BitSet, O(1), and it requires 0 <= item and item < b.size (spec/28 §9).

Specification

Generated from una v0.4.0 (docs/std/builtins.json, which is not part of the specification): built-in methods have no declaration, so una writes these signature lines and tests each against its checker. The specification governs: spec/14 §2.