Having trouble with HashMaps

I want to create a HashMap with the key being std.builtin.SourceLocation
the issue is that std.hash_map.AutoContext does not follow pointers, because it doesnt use AutoHashStrat but AutoHash, which mitigates the ability to manually input how to handle pointers.

What’s a reasonably elegant way to create a context for the hashmap that does follow pointers?

Nevermind, I solved it:

var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
const allocator = arena.allocator();

// probably the worst part about the entire std lib but oh well
// the idea and modularity is genius but the fact that std.hash_map.AutoContext
// hides the ability to choose how to handle ptrs from you just mitigates so many
// benefits
const Context = struct {
    pub const hash = std.array_hash_map
        .getAutoHashStratFn(std.builtin.SourceLocation, @This(), .Deep);
    pub const eql = std.array_hash_map
        .getAutoEqlFn(std.builtin.SourceLocation, @This());
};
var measurements = std
    .ArrayHashMap(std.builtin.SourceLocation, Measurements, Context, true).init(allocator);
3 Likes