Axle v0.22.0
Package

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 to
HashMap; 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

TypeMethod 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

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

TypeMethod and description
i64
size(self) : i64 The number of live elements held.
bool
isEmpty(self) : bool true when the set holds no live elements.
i64
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 own
control array: the two tables share the occupancy rule, not the storage.
T
elementAt(self, slot : i64) : T 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.
T
elementAtChecked(self, slot : i64) : T 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.
void
clear(mut self) : void Reset every control byte to empty and zero the live / tombstone
counters, keeping the current capacity.
bool
add(mut self, value : T) : bool 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).
bool
contains(self, value : T) : bool Membership probe — stops on the first empty (the probe chain
cannot continue past it), walking tombstones along the way.
bool
remove(mut self, value : T) : bool 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.

Method detail

#size

size(self) : i64

The number of live elements held.

#isEmpty

isEmpty(self) : bool

true when the set holds no live elements.

#nextSlot

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 own
control array: the two tables share the occupancy rule, not the storage.

Parameters
start slot to resume the search from; the loop passes the
slot after the one it just read

#elementAt

elementAt(self, slot : i64) : T

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.

Parameters
slot an occupied position nextSlot returned

#elementAtChecked

elementAtChecked(self, slot : i64) : T ! IndexOutOfBoundsException

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.

Parameters
slot position to read
Throws
IndexOutOfBoundsException when slot is out of range or not occupied.

#clear

clear(mut self) : void

Reset every control byte to empty and zero the live / tombstone
counters, keeping the current capacity.

#add

add(mut self, value : T) : bool

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).

Parameters
value element to insert; == equality decides the slot

#contains

contains(self, value : T) : bool

Membership probe — stops on the first empty (the probe chain
cannot continue past it), walking tombstones along the way.

Parameters
value element to test for membership; matched by ==

#remove

remove(mut self, value : T) : bool

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.

Parameters
value element to delete; matched by ==, no-op when absent