Module collections/hash_set
Hash set using SwissTable algorithm with set-theoretic operations.
Types
High-performance hash set using SwissTable algorithm.
Elements must implement Eq and Hash. Provides O(1) average lookup and insert.
Type Parameters
| Name | Type | Notes |
|---|---|---|
T | Type | comptime |
Trait Implementations
impl(forall(T : Type), where(T <: (Eq(T), Hash)), HashSet(T), ...)
_alloc_with_capacity : (fn(capacity: usize) -> Result(Self, HashSetError))Allocate memory for HashSet with given capacity Initializes all control bytes to EMPTY
Returns: Result(Self, HashSetError)
new : (fn() -> Self)Create a new empty HashSet with default capacity
Returns: Self
with_capacity : (fn(requested_capacity: usize) -> Self)Create a HashSet with a specific initial capacity Capacity will be rounded up to next power of 2
Returns: Self
_ctrl_ptr : (fn(self: Self) -> *(u8))Get ctrl pointer (unwrapped for internal use)
Returns: *(u8)
_data_ptr : (fn(self: Self) -> *(T))Get data pointer (unwrapped for internal use)
Returns: *(T)
_find_slot : (fn(self: Self, element: T, hash: u64) -> Option(usize))Find slot index for a given element using quadratic probing Returns Some(index) if element is found, None otherwise
Returns: Option(usize)
_find_insert_slot : (fn(self: Self, hash: u64) -> usize)Find first available slot (EMPTY or DELETED) for insertion Returns slot index using quadratic probing
Returns: usize
_needs_resize : (fn(self: Self) -> bool)Check if HashSet needs resizing based on load factor
Returns: bool
_resize : (fn(self: Self, new_capacity: usize) -> Result(unit, HashSetError))Resize and rehash the HashSet to a new capacity
Returns: Result(unit, HashSetError)
add : (fn(self: Self, element: T) -> Result(bool, HashSetError))Insert an element into the set Returns Ok(true) if element was newly inserted, Ok(false) if already present
Returns: Result(bool, HashSetError)
contains : (fn(self: Self, element: T) -> bool)Check if an element exists in the set
Returns: bool
remove : (fn(self: Self, element: T) -> bool)Remove an element from the set Returns true if the element was present and removed, false otherwise
Returns: bool
len : (fn(self: Self) -> usize)Get the number of elements in the set
Returns: usize
is_empty : (fn(self: Self) -> bool)Check if the set is empty
Returns: bool
clear : (fn(self: Self) -> unit)Clear all elements from the set Resets all control bytes to EMPTY
Returns: unit
is_subset : (fn(self: Self, other: Self) -> bool)Check if this set is a subset of another set Returns true if all elements in self are also in other
Returns: bool
is_superset : (fn(self: Self, other: Self) -> bool)Check if this set is a superset of another set Returns true if all elements in other are also in self
Returns: bool
is_disjoint : (fn(self: Self, other: Self) -> bool)Check if this set is disjoint from another set Returns true if the sets have no elements in common
Returns: bool
union : (fn(self: Self, other: Self) -> Result(Self, HashSetError))Create a new set containing the union of two sets Returns a new HashSet containing all elements from both sets
Returns: Result(Self, HashSetError)
intersection : (fn(self: Self, other: Self) -> Result(Self, HashSetError))Create a new set containing the intersection of two sets Returns a new HashSet containing only elements present in both sets
Returns: Result(Self, HashSetError)
difference : (fn(self: Self, other: Self) -> Result(Self, HashSetError))Create a new set containing the difference of two sets Returns a new HashSet containing elements in self but not in other
Returns: Result(Self, HashSetError)
symmetric_difference : (fn(self: Self, other: Self) -> Result(Self, HashSetError))Create a new set containing the symmetric difference of two sets Returns a new HashSet containing elements in either set but not in both
Returns: Result(Self, HashSetError)
impl(forall(T : Type), where(T <: (Eq(T), Hash)), HashSet(T), Dispose(...))
dispose : (fn(self: Self) -> unit)RAII destructor - automatically called when HashSet goes out of scope
Returns: unit
impl(forall(T : Type), where(T <: (Eq(T), Hash)), HashSet(T), ...)
into_iter : (fn(self : Self) -> HashSetIter(T))Returns: HashSetIter(T)
impl(forall(T : Type), where(T <: (Eq(T), Hash)), HashSet(T), ...)
iter : (fn(self : *(Self)) -> HashSetIterPtr(T))Returns: HashSetIterPtr(T)
Error variants for HashSet operations.
Variants
| Variant | Fields | Description |
|---|---|---|
AllocError | error: AllocError | Memory allocation failed. |
ElementNotFound | The element was not found in the set. | |
CapacityOverflow | Capacity calculation overflowed. |
Value iterator for HashSet - yields elements by value (T) Scans ctrl bytes to find occupied slots.
Type Parameters
| Name | Type | Notes |
|---|---|---|
T | Type | comptime |
Trait Implementations
impl(forall(T : Type), where(T <: (Eq(T), Hash)), HashSetIter(T), Iterator(...))
Item : Tnext : (fn(self : *(Self)) -> Option(T))Returns: Option(T)
Pointer iterator for HashSet - yields pointers to elements (*(T)) Pointers are valid as long as the set is not modified during iteration.
Type Parameters
| Name | Type | Notes |
|---|---|---|
T | Type | comptime |
Trait Implementations
impl(forall(T : Type), where(T <: (Eq(T), Hash)), HashSetIterPtr(T), Iterator(...))
Item : *(T)next : (fn(self : *(Self)) -> Option(*(T)))Returns: Option(*(T))