std/set
Hash set collection for unique values. Method-based on the HashSet<T> value.
from "std/set" import { HashSet }Example
var seen = HashSet<string>.new()
seen.add("alice")
seen.add("bob")
seen.add("alice") // no-op
print(intToString(seen.len())) // 2API reference
HashSet
pub struct HashSet<T>An unordered collection of unique values.
HashSet.add
fn HashSet.add(self: &mut HashSet<T>, val: T): voidAdd a value to the set.
No-op if the value is already present.
HashSet.clear
fn HashSet.clear(self: &mut HashSet<T>): voidDrop every element, keeping the table's capacity.
HashSet.clone
fn HashSet.clone(self: &HashSet<T>): HashSet<T>Element by element rather than self.inner.clone(): the builtin map clone copies each key structurally and never runs T's own Clone impl, so a T carrying Drop was released once per copy (the generic-drop fuzzer's HashSet.clone finding). Same reason every other constructor here spells x.clone().
HashSet.contains
fn HashSet.contains(self: &HashSet<T>, val: T): boolCheck if the set contains a value.
HashSet.difference
fn HashSet.difference(self: &HashSet<T>, other: &HashSet<T>): HashSet<T>Everything in this set that is not in other.
HashSet.fromVec
fn HashSet.fromVec(items: Vec<T>): HashSet<T>Collect a Vec into a set, dropping duplicates.
HashSet.intersect
fn HashSet.intersect(self: &HashSet<T>, other: &HashSet<T>): HashSet<T>Everything in both sets.
HashSet.isEmpty
fn HashSet.isEmpty(self: &HashSet<T>): boolHashSet.isSubsetOf
fn HashSet.isSubsetOf(self: &HashSet<T>, other: &HashSet<T>): boolTrue when every element of this set is also in other.
HashSet.len
fn HashSet.len(self: &HashSet<T>): i64Number of elements in the set.
HashSet.new
fn HashSet.new(): HashSet<T>Create an empty HashSet.
A generic static takes its type argument: HashSet<string>.new().
HashSet.remove
fn HashSet.remove(self: &mut HashSet<T>, val: T): voidRemove a value from the set.
No-op if the value is absent.
HashSet.toVec
fn HashSet.toVec(self: &HashSet<T>): Vec<T>Snapshot the elements into a Vec. Sort it if you need a stable order — print on a set would otherwise expose the randomized bucket order. Not self.inner.keys(), for the reason clone gives.
HashSet.union
fn HashSet.union(self: &HashSet<T>, other: &HashSet<T>): HashSet<T>Everything in either set.
HashSet.withCapacity
fn HashSet.withCapacity(capacity: i64): HashSet<T>Create an empty HashSet sized so capacity adds never rehash.