4 ms·
I would assume that is because the hash table takes in a “hash this key” function pointer and a “compare these keys” function pointer, and those must contain th
by Sesse__ 2y ago
I would assume that is because the hash table takes in a “hash this key” function pointer and a “compare these keys” function pointer, and those must contain the size for variable-length keys. So even if your user-supplied functions know the length, or only care about the first byte, they have to conform to that API, and then you get an unused parameter.
- zabzonk 2y agoHave functions with different names and different numbers of parameters?
- Sesse__ 2y agoAnd then have a union between the two different kinds of pointers, and a tag to tell which one is in use, then test that tag everywhere? Why? What good does it bring for that extra complexity?
- zabzonk 2y agoDoesn't the name of the function select for the types and use of the parameters? But I haven't written in C for a long time, and this I think could be done more clearly in C++.
- saagarjha 2y agoThat would be a bad API design.
- detaro 2y agoThe point is that you can pass any of the hash functions (or your own compatible) to the datastructure, so it'll obviously call of them with the same set of parameters. And hash functions that need all of them will ignore them.