Set API Reference

Hash-based set collection for i64 values

Import

U std/set

Struct

S Set { buckets: i64, size: i64, cap: i64 }

Methods

MethodSignatureDescription
with_capacityF with_capacity(capacity: i64) -> SetCreate with capacity
lenF len(&self) -> i64Number of elements
capacityF capacity(&self) -> i64Number of buckets
is_emptyF is_empty(&self) -> i64Check if empty
containsF contains(&self, value: i64) -> i64Check membership
insertF insert(&self, value: i64) -> i64Add element (returns 1 if newly inserted)
removeF remove(&self, value: i64) -> i64Remove element (returns 1 if found)
clearF clear(&self) -> i64Remove all
unionF union(&self, other: Set) -> SetCreate set with all elements from both
intersectionF intersection(&self, other: Set) -> SetCreate set with common elements
differenceF difference(&self, other: Set) -> SetCreate set with elements in self but not other
symmetric_differenceF symmetric_difference(&self, other: Set) -> SetElements in either but not both
is_subsetF is_subset(&self, other: Set) -> i64Check if all elements in other
is_supersetF is_superset(&self, other: Set) -> i64Check if contains all of other
is_disjointF is_disjoint(&self, other: Set) -> i64Check if no common elements
dropF drop(&self) -> i64Free memory

Free Functions

FunctionSignatureDescription
set_newF set_new() -> SetCreate new Set with default capacity (16)

Usage

U std/set

F main() -> i64 {
    s1 := set_new()
    s1.insert(10)
    s1.insert(20)
    s1.contains(10)  # 1

    s2 := Set.with_capacity(16)
    s2.insert(20)
    s2.insert(30)

    union_set := s1.union(s2)  # {10, 20, 30}
    inter_set := s1.intersection(s2)  # {20}

    s1.drop()
    s2.drop()
    union_set.drop()
    inter_set.drop()
    0
}