shared: use siphash24() for nm_hash_ptr()

siphash24() mixes the bits much better then our naive xor.
Don't bypass siphash24(). We supposedly use it for the
better hashing properties, so use it also for pointers.
This commit is contained in:
Thomas Haller 2017-11-15 15:33:32 +01:00
parent c3d98a3df6
commit ecd106101b
2 changed files with 10 additions and 9 deletions

View file

@ -175,6 +175,10 @@ test_nm_hash (void)
g_assert (nm_hash_str (""));
g_assert (nm_hash_str ("a"));
g_assert (nm_hash_ptr (NULL));
g_assert (nm_hash_ptr (""));
g_assert (nm_hash_ptr ("a"));
_test_hash_str ("");
_test_hash_str ("a");
_test_hash_str ("aa");

View file

@ -143,16 +143,13 @@ nm_str_hash (gconstpointer str)
guint
nm_hash_ptr (gconstpointer ptr)
{
guint h;
NMHashState h;
h = ((const guint *) _get_hash_key ())[0];
if (sizeof (ptr) <= sizeof (guint))
h = h ^ ((guint) ((uintptr_t) ptr));
else
h = h ^ ((guint) (((guint64) (uintptr_t) ptr) >> 32)) ^ ((guint) ((uintptr_t) ptr));
return h ?: 2907677551u;
if (!ptr)
return nm_hash_static (2907677551u);
nm_hash_init (&h, 2907677551u);
nm_hash_update (&h, &ptr, sizeof (ptr));
return nm_hash_complete (&h);
}
guint