I‘ve argued for quite some time with a friend about wether or not this C# method can be qualified as a Hash Function.
public override int GetHashCode() {
return X.GetHashCode() * 31 + Y.GetHashCode();
}
My argument is that this simply returns a 32-bit integer value, using a fixed input size of 2 variable 32-bit integer values (and one constant 32-bit integer value), while one of the prerequisites for a Hash Function is an arbitrary input size. Using two 32-bit integer inputs is not arbitrary as far as i can tell. Unless arbitrary refers to the possibility in general (meaning 2 different functions can have fixed-size input, but the specific sizes aren‘t limited and can be different for each) and not the need for each function to have the ability to accept an arbitrary input size, while returning the output with the same size, no matter the input size.
The values of X.GetHashCode() and Y.GetHashCode() are variable 32-bit integer values and are the result of a Hash Function.
Now, the way i see it, you can just simplify that code to: h(x, y)=x*31+y , where x and y are 32-bit integer values. Which leaves you with 64-bit fixed input size, so either my simplification is faulted, or it‘s not a Hash Function, correct?
If that simplification is not correct, why not?
And what exactly dis/qualifies this as a Hash Function?
Does the input values being the results of a Hash Function affect the qualification of the code as a Hash Function in any way? Even if it is guaranteed that the inputs will be the result of a Hash Function, that doesn‘t make this function a Hash Function, does it? (Like how 'f(log2(4), log2(3)) , where f(x, y) = x+y' would not be a logarithmic function just because of the inputs.)
Thank you for your time. Any suggestion is much appreciated. Also, sorry if some parts are unclear or poorly formatted. I‘m not really versed in this, be it the mathemathical definitions, the language, or stackexchange in general.