Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Public Function

shrinkAndFreeContext

Public Function
std.array_hash_map.ArrayHashMap.shrinkAndFreeContext
pub fn shrinkAndFreeContext(self: *Self, gpa: Allocator, new_len: usize, ctx: Context) void

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.

Params

File

array_hash_map.zig:1022
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
        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);
        }