HashMap is now Printable. Fix access inlining for enums. #1958

This commit is contained in:
Christoffer Lerno
2025-02-12 23:11:46 +01:00
parent c9ecb09cd7
commit 1f856cacf5
6 changed files with 55 additions and 6 deletions

View File

@@ -6,8 +6,9 @@
*>
module std::collections::map(<Key, Value>);
import std::math;
import std::io @norecurse;
struct HashMap
struct HashMap (Printable)
{
Entry*[] table;
Allocator allocator;
@@ -446,6 +447,18 @@ fn void HashMap.resize(&map, uint new_capacity) @private
map.threshold = (uint)(new_capacity * map.load_factor);
}
fn usz! HashMap.to_format(&self, Formatter* f) @dynamic
{
usz len;
len += f.print("{ ")!;
self.@each_entry(; Entry* entry)
{
if (len > 2) len += f.print(", ")!;
len += f.printf("%s: %s", entry.key, entry.value)!;
};
return len + f.print(" }");
}
fn void HashMap.transfer(&map, Entry*[] new_table) @private
{
Entry*[] src = map.table;