fn ArrayHashMap(comptime K: type, comptime V: type, comptime Context: type, comptime store_hash: bool) type

Insertion order is preserved. Deletions perform a “swap removal” on the entries list. Modifying the hash map while iterating is allowed, however, one must understand the (well defined) behavior when mixing insertions and deletions with iteration. For a hash map that can be initialized directly that does not store an Allocator field, see ArrayHashMapUnmanaged. When store_hash is false, this data structure is biased towards cheap eql functions. It does not store each item’s hash in the table. Setting store_hash to true incurs slightly more memory cost by storing each key’s hash in the table but only has to call eql for hash collisions. If typical operations (except iteration over entries) need to be faster, prefer the alternative std.HashMap. Context must be a struct type with two member functions: hash(self, K) u32 eql(self, K, K, usize) bool Adapted variants of many functions are provided. These variants take a pseudo key instead of a key. Their context must have the functions: hash(self, PseudoKey) u32 eql(self, PseudoKey, K, usize) bool

Parameters

K: type,
V: type,
Context: type,
store_hash: bool,

Fields

unmanaged: Unmanaged,
allocator: Allocator,
ctx: Context,

Functions

fn capacity(self: Self) usize

Returns the number of total elements which may be present before it is no longe…

Returns the number of total elements which may be present before it is no longer guaranteed that no allocations will be performed.

fn clearAndFree(self: *Self) void

Clears the map and releases the backing allocation

fn clearRetainingCapacity(self: *Self) void

Clears the map but retains the backing allocation for future use.

fn clone(self: Self) !Self

Create a copy of the hash map which can be modified separately. The copy uses t…

Create a copy of the hash map which can be modified separately. The copy uses the same context and allocator as this instance.

fn cloneWithAllocator(self: Self, allocator: Allocator) !Self

Create a copy of the hash map which can be modified separately. The copy uses t…

Create a copy of the hash map which can be modified separately. The copy uses the same context as this instance, but the specified allocator.

fn cloneWithAllocatorAndContext(self: Self, allocator: Allocator, ctx: anytype) !ArrayHashMap(K, V, @TypeOf(ctx), store_hash)

Create a copy of the hash map which can be modified separately. The copy uses t…

Create a copy of the hash map which can be modified separately. The copy uses the specified allocator and context.

fn cloneWithContext(self: Self, ctx: anytype) !ArrayHashMap(K, V, @TypeOf(ctx), store_hash)

Create a copy of the hash map which can be modified separately. The copy uses t…

Create a copy of the hash map which can be modified separately. The copy uses the same allocator as this instance, but the specified context.

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

Check whether a key is stored in the map

fn containsAdapted(self: Self, key: anytype, ctx: anytype) bool

No documentation provided.

fn count(self: Self) usize

Returns the number of KV pairs stored in this map.

fn deinit(self: *Self) void

Frees the backing allocation and leaves the map in an undefined state. Note tha…

Frees the backing allocation and leaves the map in an undefined state. Note that this does not free keys or values. You must take care of that before calling this function, if it is needed.

fn ensureTotalCapacity(self: *Self, new_capacity: usize) !void

Increases capacity, guaranteeing that insertions up until the expected_count

Increases capacity, guaranteeing that insertions up until the expected_count will not cause an allocation, and therefore cannot fail.

fn ensureUnusedCapacity(self: *Self, additional_count: usize) !void

Increases capacity, guaranteeing that insertions up until additional_count **…

Increases capacity, guaranteeing that insertions up until additional_count more items will not cause an allocation, and therefore cannot fail.

fn fetchOrderedRemove(self: *Self, key: K) ?KV

If there is an Entry with a matching key, it is deleted from the hash map, an…

If there is an Entry with a matching key, it is deleted from the hash map, and then returned from this function. The entry is removed from the underlying array by shifting all elements forward thereby maintaining the current ordering.

fn fetchOrderedRemoveAdapted(self: *Self, key: anytype, ctx: anytype) ?KV

No documentation provided.

fn fetchPut(self: *Self, key: K, value: V) !?KV

Inserts a new Entry into the hash map, returning the previous one, if any.

fn fetchPutAssumeCapacity(self: *Self, key: K, value: V) ?KV

Inserts a new Entry into the hash map, returning the previous one, if any. If…

Inserts a new Entry into the hash map, returning the previous one, if any. If insertion happuns, asserts there is enough capacity without allocating.

fn fetchSwapRemove(self: *Self, key: K) ?KV

If there is an Entry with a matching key, it is deleted from the hash map, an…

If there is an Entry with a matching key, it is deleted from the hash map, and then returned from this function. The entry is removed from the underlying array by swapping it with the last element.

fn fetchSwapRemoveAdapted(self: *Self, key: anytype, ctx: anytype) ?KV

No documentation provided.

fn get(self: Self, key: K) ?V

Find the value associated with a key

fn getAdapted(self: Self, key: anytype, ctx: anytype) ?V

No documentation provided.

fn getEntry(self: Self, key: K) ?Entry

Finds pointers to the key and value storage associated with a key.

fn getEntryAdapted(self: Self, key: anytype, ctx: anytype) ?Entry

No documentation provided.

fn getIndex(self: Self, key: K) ?usize

Finds the index in the entries array where a key is stored

fn getIndexAdapted(self: Self, key: anytype, ctx: anytype) ?usize

No documentation provided.

fn getKey(self: Self, key: K) ?K

Find the actual key associated with an adapted key

fn getKeyAdapted(self: Self, key: anytype, ctx: anytype) ?K

No documentation provided.

fn getKeyPtr(self: Self, key: K) ?*K

Find a pointer to the actual key associated with an adapted key

fn getKeyPtrAdapted(self: Self, key: anytype, ctx: anytype) ?*K

No documentation provided.

fn getOrPut(self: *Self, key: K) !GetOrPutResult

If key exists this function cannot fail. If there is an existing item with `key…

If key exists this function cannot fail. If there is an existing item with key, then the result Entry pointer points to it, and found_existing is true. Otherwise, puts a new item with undefined value, and the Entry pointer points to it. Caller should then initialize the value (but not the key).

fn getOrPutAdapted(self: *Self, key: anytype, ctx: anytype) !GetOrPutResult

No documentation provided.

fn getOrPutAssumeCapacity(self: *Self, key: K) GetOrPutResult

If there is an existing item with key, then the result Entry pointer points…

If there is an existing item with key, then the result Entry pointer points to it, and found_existing is true. Otherwise, puts a new item with undefined value, and the Entry pointer points to it. Caller should then initialize the value (but not the key). If a new entry needs to be stored, this function asserts there is enough capacity to store it.

fn getOrPutAssumeCapacityAdapted(self: *Self, key: anytype, ctx: anytype) GetOrPutResult

No documentation provided.

fn getOrPutValue(self: *Self, key: K, value: V) !GetOrPutResult

No documentation provided.

fn getPtr(self: Self, key: K) ?*V

Find a pointer to the value associated with a key

fn getPtrAdapted(self: Self, key: anytype, ctx: anytype) ?*V

No documentation provided.

fn init(allocator: Allocator) Self

Create an ArrayHashMap instance which will use a specified allocator.

fn initContext(allocator: Allocator, ctx: Context) Self

No documentation provided.

fn iterator(self: *const Self) Iterator

Returns an iterator over the pairs in this map. Modifying the map may invalidat…

Returns an iterator over the pairs in this map. Modifying the map may invalidate this iterator.

fn keys(self: Self) []K

Returns the backing array of keys in this map. Modifying the map may invalidate…

Returns the backing array of keys in this map. Modifying the map may invalidate this array.

fn move(self: *Self) Self

Set the map to an empty state, making deinitialization a no-op, and returning a…

Set the map to an empty state, making deinitialization a no-op, and returning a copy of the original.

fn orderedRemove(self: *Self, key: K) bool

If there is an Entry with a matching key, it is deleted from the hash map. Th…

If there is an Entry with a matching key, it is deleted from the hash map. The entry is removed from the underlying array by shifting all elements forward, thereby maintaining the current ordering. Returns true if an entry was removed, false otherwise.

fn orderedRemoveAdapted(self: *Self, key: anytype, ctx: anytype) bool

No documentation provided.

fn orderedRemoveAt(self: *Self, index: usize) void

Deletes the item at the specified index in entries from the hash map. The ent…

Deletes the item at the specified index in entries from the hash map. The entry is removed from the underlying array by shifting all elements forward, thereby maintaining the current ordering.

fn pop(self: *Self) KV

Removes the last inserted Entry in the hash map and returns it.

fn popOrNull(self: *Self) ?KV

Removes the last inserted Entry in the hash map and returns it if count is non…

Removes the last inserted Entry in the hash map and returns it if count is nonzero. Otherwise returns null.

fn put(self: *Self, key: K, value: V) !void

Clobbers any existing data. To detect if a put would clobber existing data, see…

Clobbers any existing data. To detect if a put would clobber existing data, see getOrPut.

fn putAssumeCapacity(self: *Self, key: K, value: V) void

Asserts there is enough capacity to store the new key-value pair. Clobbers any …

Asserts there is enough capacity to store the new key-value pair. Clobbers any existing data. To detect if a put would clobber existing data, see getOrPutAssumeCapacity.

fn putAssumeCapacityNoClobber(self: *Self, key: K, value: V) void

Asserts there is enough capacity to store the new key-value pair. Asserts that …

Asserts there is enough capacity to store the new key-value pair. Asserts that it does not clobber any existing data. To detect if a put would clobber existing data, see getOrPutAssumeCapacity.

fn putNoClobber(self: *Self, key: K, value: V) !void

Inserts a key-value pair into the hash map, asserting that no previous entry wi…

Inserts a key-value pair into the hash map, asserting that no previous entry with the same key is already present

fn reIndex(self: *Self) !void

Rebuilds the key indexes. If the underlying entries has been modified directly, …

Rebuilds the key indexes. If the underlying entries has been modified directly, users can call reIndex to update the indexes to account for these new entries.

fn shrinkAndFree(self: *Self, new_len: usize) void

Shrinks the underlying Entry array to new_len elements and discards any asso…

Shrinks the underlying Entry array to new_len elements and discards any associated index entries. Reduces allocated capacity.

fn shrinkRetainingCapacity(self: *Self, new_len: usize) void

Shrinks the underlying Entry array to new_len elements and discards any asso…

Shrinks the underlying Entry array to new_len elements and discards any associated index entries. Keeps capacity the same.

fn sort(self: *Self, sort_ctx: anytype) void

Sorts the entries and then rebuilds the index. sort_ctx must have this method…

Sorts the entries and then rebuilds the index. sort_ctx must have this method: fn lessThan(ctx: @TypeOf(ctx), a_index: usize, b_index: usize) bool

fn swapRemove(self: *Self, key: K) bool

If there is an Entry with a matching key, it is deleted from the hash map. Th…

If there is an Entry with a matching key, it is deleted from the hash map. The entry is removed from the underlying array by swapping it with the last element. Returns true if an entry was removed, false otherwise.

fn swapRemoveAdapted(self: *Self, key: anytype, ctx: anytype) bool

No documentation provided.

fn swapRemoveAt(self: *Self, index: usize) void

Deletes the item at the specified index in entries from the hash map. The ent…

Deletes the item at the specified index in entries from the hash map. The entry is removed from the underlying array by swapping it with the last element.

fn values(self: Self) []V

Returns the backing array of values in this map. Modifying the map may invalida…

Returns the backing array of values in this map. Modifying the map may invalidate this array.

Values

Data
undefined

The Data type used for the MultiArrayList backing this map

DataList
undefined

The MultiArrayList type backing this map

Entry
undefined

Pointers to a key and value in the backing store of this map. Modifying the key…

GetOrPutResult
undefined

getOrPut variants return this structure, with pointers to the backing store and…

Hash
undefined

The stored hash type, either u32 or void.

Iterator
undefined

An Iterator over Entry pointers.

KV
undefined

A KV pair which has been copied out of the backing store

Unmanaged
undefined

The ArrayHashMapUnmanaged type using the same settings as this managed map.