cloneContext
Function parameters
Parameters
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 cloneContext(self: Self, allocator: Allocator, new_ctx: anytype) Allocator.Error!HashMapUnmanaged(K, V, @TypeOf(new_ctx), max_load_percentage) {
var other: HashMapUnmanaged(K, V, @TypeOf(new_ctx), max_load_percentage) = .empty;
if (self.size == 0)
return other;
const new_cap = capacityForSize(self.size);
try other.allocate(allocator, new_cap);
other.initMetadatas();
other.available = @truncate((new_cap * max_load_percentage) / 100);
var i: Size = 0;
var metadata = self.metadata.?;
const keys_ptr = self.keys();
const values_ptr = self.values();
while (i < self.capacity()) : (i += 1) {
if (metadata[i].isUsed()) {
other.putAssumeCapacityNoClobberContext(keys_ptr[i], values_ptr[i], new_ctx);
if (other.size == self.size)
break;
}
}
return other;
}