getOrPutContextAdapted
Function parameters
Parameters
Type definitions in this namespace
Types
An `ArrayHashMap` with default hash and equal functions.
Functions
- AutoArrayHashMap
- An `ArrayHashMap` with default hash and equal functions.
- AutoArrayHashMapUnmanaged
- An `ArrayHashMapUnmanaged` with default hash and equal functions.
- StringArrayHashMap
- An `ArrayHashMap` with strings as keys.
- StringArrayHashMapUnmanaged
- An `ArrayHashMapUnmanaged` with strings as keys.
- ArrayHashMap
- Deprecated in favor of `ArrayHashMapWithAllocator` (no code changes needed)
- ArrayHashMapWithAllocator
- A hash table of keys and values, each stored sequentially.
- ArrayHashMapUnmanaged
- A hash table of keys and values, each stored sequentially.
Source
Implementation
pub fn getOrPutContextAdapted(self: *Self, gpa: Allocator, key: anytype, key_ctx: anytype, ctx: Context) Oom!GetOrPutResult {
self.ensureTotalCapacityContext(gpa, self.entries.len + 1, ctx) catch |err| {
// "If key exists this function cannot fail."
const index = self.getIndexAdapted(key, key_ctx) orelse return err;
const slice = self.entries.slice();
return GetOrPutResult{
.key_ptr = &slice.items(.key)[index],
// workaround for #6974
.value_ptr = if (@sizeOf(*V) == 0) undefined else &slice.items(.value)[index],
.found_existing = true,
.index = index,
};
};
return self.getOrPutAssumeCapacityAdapted(key, key_ctx);
}