Because of the word limit on the title, I could not specify what I meant by "perfect hash function" and "best hash function".
h, the perfect hash function is only perfect regarding the impossibility of collision, not its distribution.
The hash function of c3
should be solely implemented based on its two fields of type c1
and c2
, and it should be able to avoid collisions, but not necessarily offer a good distribution of hashes.
Whatever the answer, I would like an explanation for the Math behind the function, and why it avoids collisions, so I can aim for that same Math next time I'm in a similar situation.
(The code bellow is written in C#, but the problem is general enough to not award it the [C#] tag)
EDIT: Note that all hash functions involved need to return a 32bits integer.
class C3
{
C1 _c1Field;
C2 _c2Field;
public override int GetHashCode()
{
//what to do here?
}
}
EDIT2: The thing about claiming my question is a duplicate is this: I don't want a good hash function according to normal standards. I thought I made that clear enough, but apparently I didn't. I need a hash function that completely ignores uniformity of distribution. I don't need to care about that at all. I just need a function that avoids collision. I'm not asking it to be perfect, and to never collide, that would be silly. I'm asking for a function that, given two images under our ideal (and purely hypothetical) h function, would output an image with a minimized chance of collision with another, different pair of images under h.
I don't know any other name for that kind of function, so I'm calling it a hash function. It may be that the problem lies with my lack of specialized vocabulary, as I only code as hobby and out of love, not for a living.