fn EnumMap(comptime E: type, comptime V: type) type

A map keyed by an enum, backed by a bitfield and a dense array. If the enum is not dense, a mapping will be constructed from enum values to dense indices. This type does no dynamic allocation and can be copied by value.

Parameters

E: type,
V: type,

Fields

bits: BitSet = field_call,

Bits determining whether items are in the map

values: [Indexer.count]Value = undefined,

Values of items in the map. If the associated bit is zero, the value is undefined.

Functions

fn contains(self: Self, key: Key) bool

Checks if the map contains an item.

fn count(self: Self) usize

The number of items in the map.

fn fetchPut(self: *Self, key: Key, value: Value) ?Value

Sets the value associated with the key in the map, and returns the old value. …

Sets the value associated with the key in the map, and returns the old value. If the key was not in the map, returns null.

fn fetchRemove(self: *Self, key: Key) ?Value

Removes a key from the map, and returns the old value. If the key was not in th…

Removes a key from the map, and returns the old value. If the key was not in the map, returns null.

fn get(self: Self, key: Key) ?Value

Gets the value associated with a key. If the key is not in the map, returns nul…

Gets the value associated with a key. If the key is not in the map, returns null.

fn getAssertContains(self: Self, key: Key) Value

Gets the value associated with a key, which must exist in the map.

fn getPtr(self: *Self, key: Key) ?*Value

Gets the address of the value associated with a key. If the key is not in the m…

Gets the address of the value associated with a key. If the key is not in the map, returns null.

fn getPtrAssertContains(self: *Self, key: Key) *Value

Gets the address of the value associated with a key. The key must be present in…

Gets the address of the value associated with a key. The key must be present in the map.

fn getPtrConst(self: *const Self, key: Key) ?*const Value

Gets the address of the const value associated with a key. If the key is not in…

Gets the address of the const value associated with a key. If the key is not in the map, returns null.

fn iterator(self: *Self) Iterator

Returns an iterator over the map, which visits items in index order. Modificati…

Returns an iterator over the map, which visits items in index order. Modifications to the underlying map may or may not be observed by the iterator, but will not invalidate it.

fn put(self: *Self, key: Key, value: Value) void

Adds the key to the map with the supplied value. If the key is already in the m…

Adds the key to the map with the supplied value. If the key is already in the map, overwrites the value.

fn putUninitialized(self: *Self, key: Key) *Value

Adds the key to the map with an undefined value. If the key is already in the m…

Adds the key to the map with an undefined value. If the key is already in the map, the value becomes undefined. A pointer to the value is returned, which should be used to initialize the value.

fn remove(self: *Self, key: Key) void

Removes a key from the map. If the key was not in the map, does nothing.

Values

Indexer
undefined

The index mapping for this map

Key
undefined

The key type used to index this map

Value
undefined

The value type stored in this map

len
undefined

The number of possible keys in the map