Hi, so I’m currently trying to use a HashMap in Zig, I just have problem with the Context parameter, as I understand this is a small struct containing two custom functions one for equality “eql” and one for hashing “hash”, so I’ve declared a small struct like this :
Of course it doesn’t work, I was pretty sure undefined wasn’t the correct answer and I was right, but I still don’t understand how I’m supposed to do it, so if someone could provide some guidance, that would be really helpful. I’m not sure do I need to declare member functions ? if so what is the syntax around that, basically I just want a basic string comparison for the equality and any hash will do, I just need the hash map, to identify duplicates.
First, you don’t need to make a function returning a struct if it isn’t parameterized, you can just declare it like this:
const StructName = struct {
// ...
};
Secondly, this would make eql and hash members of instances of your struct, not member functions which are constant in type. Member functions are declared like this:
Very helpful, article, I should have looked a bit more on google, so basically for my usecase I can probably get away with using StringHashMap, or I can just provide a simple struct if I want a more custom behavior, Thanks for the response it’s very helpful,