DoxigAlpha

removeByPtr

Delete the entry with key pointed to by key_ptr from the hash map. key_ptr is assumed to be a valid pointer to a key that is present in the hash map.

TODO: answer the question in these doc comments, does this increase the unused capacity by one?

Function parameters

Parameters

#
self:*Self
key_ptr:*K

Type definitions in this namespace

Types

#

Functions in this namespace

Functions

#
StringHashMap
Builtin hashmap for strings as keys.
StringHashMapUnmanaged
Key memory is managed by the caller.
HashMap
General purpose hash table.
HashMapUnmanaged
A HashMap based on open addressing and linear probing.

= 80

Values

#

Source

Implementation

#
pub fn removeByPtr(self: *Self, key_ptr: *K) void {
    // TODO: replace with pointer subtraction once supported by zig
    // if @sizeOf(K) == 0 then there is at most one item in the hash
    // map, which is assumed to exist as key_ptr must be valid.  This
    // item must be at index 0.
    const idx = if (@sizeOf(K) > 0)
        (@intFromPtr(key_ptr) - @intFromPtr(self.keys())) / @sizeOf(K)
    else
        0;

    self.removeByIndex(idx);
}