std/collections/hashset
std/collections/hashset — generic HashSet<T> over the hashable
mono dimensions (i32 / i64 / string).
A SwissTable membership set — the HashMap SwissTable with the
parallel value array removed (add either inserts the element or
reports it was already present; there is nothing to store
alongside it). The meta-byte / h2 / probe machinery is identical toHashMap; see collections.axle for the full layout commentary.
meta : i8[cap + 16] — control byte per slot + 16-byte mirror.
keys : T[cap] — the elements.
Meta encoding: 0x00..0x7F occupied (low 7 bits = h2), 0x80
empty, 0xFE tombstone. Hashing dispatches statically per T via
the hash_key builtin; load factor 7/8 (len + tombstones feeds
the trigger). Rehash re-inserts the live elements, dropping tombstones,
into a table 4x (small) or 2x (large) the size, or the same size when the
live elements fill at most half of it.T = f64 is unsupported: hash_key rejects floats (NaN, ±0, and
precision-as-equality are footguns), exactly as HashMap rejects
an f64 key. Collect floats in an ArrayList<f64> instead.
C class HashSet<T>
Constructors
| Type | Method and description |
|---|---|
| constructor() Build an empty set sized to one 16-slot SIMD group, its meta array (plus 16-byte mirror) splatted to the empty sentinel. |
Method detail
#constructor
Build an empty set sized to one 16-slot SIMD group, its meta
array (plus 16-byte mirror) splatted to the empty sentinel.
Methods
| Type | Method and description |
|---|---|
| size(self) : i64 The number of live elements held. |
| isEmpty(self) : bool true when the set holds no live elements. |
| nextSlot(self, start : i64) : i64 The first occupied slot at or after start, or -1 when none remains.A slot is occupied when its control byte has the high bit clear (an empty or tombstoned slot has it set). One half of the pair for (x of set) walks by, with elementAt; the order is the table's,not insertion order. The scan is HashMap.nextSlot's, written out in each class over its owncontrol array: the two tables share the occupancy rule, not the storage. |
| elementAt(self, slot : i64) : T The element in slot, a value nextSlot returned. This is the iterationprotocol's read: it cannot raise, and a slot nextSlot did not return abortsthe process with a message instead of reading a released key. Use elementAtChecked for any otherslot. |
| elementAtChecked(self, slot : i64) : T The element in slot, refusing a position that is out of range or holdsno live element. A removed slot is a tombstone whose key was released, so reading it through elementAt is a use after free. |
| clear(mut self) : void Reset every control byte to empty and zero the live / tombstone counters, keeping the current capacity. |
| add(mut self, value : T) : bool Insert value if absent. Returns true when it was newlyinserted, false when an equal element was already present.Grows past the 7/8 load factor first, then SIMD-probes for the element (already present → no-op) or the first hole (insert, reclaiming a tombstone slot when one is chosen). |
| contains(self, value : T) : bool Membership probe — stops on the first empty (the probe chain cannot continue past it), walking tombstones along the way. |
| remove(mut self, value : T) : bool Delete value. Marks the slot as a tombstone (0xFE) rather thanempty so existing probe chains through it stay intact; the tombstone counter feeds the rehash trigger. Returns true whenan element was removed. |
Method detail
#size
The number of live elements held.
#isEmpty
true when the set holds no live elements.
#nextSlot
The first occupied slot at or after start, or -1 when none remains.
A slot is occupied when its control byte has the high bit clear (an
empty or tombstoned slot has it set). One half of the pairfor (x of set) walks by, with elementAt; the order is the table's,
not insertion order.
The scan is HashMap.nextSlot's, written out in each class over its own
control array: the two tables share the occupancy rule, not the storage.
start slot to resume the search from; the loop passes theslot after the one it just read
#elementAt
The element in slot, a value nextSlot returned. This is the iteration
protocol's read: it cannot raise, and a slot nextSlot did not return aborts
the process with a message instead of reading a released key. Use elementAtChecked for any other
slot.
slot an occupied position nextSlot returned#elementAtChecked
The element in slot, refusing a position that is out of range or holds
no live element. A removed slot is a tombstone whose key was released, so
reading it through elementAt is a use after free.
slot position to readIndexOutOfBoundsException when slot is out of range or not occupied.#clear
Reset every control byte to empty and zero the live / tombstone
counters, keeping the current capacity.
#add
Insert value if absent. Returns true when it was newly
inserted, false when an equal element was already present.
Grows past the 7/8 load factor first, then SIMD-probes for the
element (already present → no-op) or the first hole (insert,
reclaiming a tombstone slot when one is chosen).
value element to insert; == equality decides the slot#contains
Membership probe — stops on the first empty (the probe chain
cannot continue past it), walking tombstones along the way.
value element to test for membership; matched by ==#remove
Delete value. Marks the slot as a tombstone (0xFE) rather than
empty so existing probe chains through it stay intact; the
tombstone counter feeds the rehash trigger. Returns true when
an element was removed.
value element to delete; matched by ==, no-op when absent