I would like to do structural hashing in a C# array, and I dont know how to do so. This seems like a very basic and very simple question in any language, but I can't make it work in C#...
I have an array of 383 double. when I hash it, I get a very odd value
// this returns 134217728
let h = ((IStructuralEquatable) data).GetHashCode(EqualityComparer<double>.Default)
which happens to be such that ln h / ln 2 = 27
...
How can one get in C# the structural hashcode of an array of hashable stuff ?
Edit better illustration
In particular the following code would produce stupid results
var vala = new[] { 1f, 354652f, 3f };
var valb = new[] { 1f, 56f, 545013f };
var valc = new[] { 1f, 2584356483f, 68763948475f };
var hashA = ((IStructuralEquatable)vala).GetHashCode(EqualityComparer<float>.Default);
var hashB = ((IStructuralEquatable)valb).GetHashCode(EqualityComparer<float>.Default);
var hashC = ((IStructuralEquatable)valc).GetHashCode(EqualityComparer<float>.Default);
the hash is consistently 796917760
. (it seem to change with the 1st number though...)
Conclusion
The conclusion seems to be that structural hashing is just broken in C#, in practical terms.
(of course litterally, it is not, as others have argued an almost constant function is a valid hash function.....)