Bad handling of double as key to GHashTable
Submitted by Lucas Clemente Vella
After trying to use GHashTable in my application, with an array of 3 doubles as key, I noticed from inside my hash function that all values returned from g_double_hash were zero.
Considering it is a very common use case having in all your doubles numbers between [0, 1), as it is my case, it is terrible to simply cast the value to guint and use it as a hash, as done in the current version of g_double_hash.
So this I made this patch with a new implementation of g_double_hash, that takes into account all the bytes of a gdouble, preventing such common collisions. The constant and the expression came from here: http://stackoverflow.com/questions/2590677/how-do-i-combine-hash-values-in-c0x
It also take into accounts different double values that compares as equals (namely, 0.0 == -0.0), and NaN's, that never compares as equals (NAN != NAN). For this last, I had to change g_double_equal too.
Pull request link: https://github.com/GNOME/glib/pull/7