shrinkAndFreeContext
Shrinks the underlying Entry array to new_len elements and
discards any associated index entries. Reduces allocated capacity.
Asserts the discarded entries remain initialized and capable of
performing hash and equality checks. It is a bug to call this
function if the discarded entries require deinitialization. For
that use case, shrinkRetainingCapacityContext can be used
instead.
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 shrinkAndFreeContext(self: *Self, gpa: Allocator, new_len: usize, ctx: Context) void {
self.pointer_stability.lock();
defer self.pointer_stability.unlock();
// Remove index entries from the new length onwards.
// Explicitly choose to ONLY remove index entries and not the underlying array list
// entries as we're going to remove them in the subsequent shrink call.
if (self.index_header) |header| {
var i: usize = new_len;
while (i < self.entries.len) : (i += 1)
self.removeFromIndexByIndex(i, if (store_hash) {} else ctx, header);
}
self.entries.shrinkAndFree(gpa, new_len);
}