shared: add nm_ppdirect_hash()/nm_ppdirect_equal() helpers

Useful for hashing pointers to a pointer to a pointer, and
compare the resulting pointer directly. This will be actually
used.
This commit is contained in:
Thomas Haller
2019-10-27 09:23:39 +01:00
parent 86352ceaf8
commit d21439eaa0
2 changed files with 40 additions and 1 deletions

View File

@@ -206,3 +206,34 @@ nm_pdirect_equal (gconstpointer a, gconstpointer b)
&& s2
&& *s1 == *s2);
}
guint
nm_ppdirect_hash (gconstpointer p)
{
const void *const*const*s = p;
if (!s)
return nm_hash_static (396534869u);
if (!*s)
return nm_hash_static (1476102263u);
return nm_direct_hash (**s);
}
gboolean
nm_ppdirect_equal (gconstpointer a, gconstpointer b)
{
const void *const*const*s1 = a;
const void *const*const*s2 = b;
if (s1 == s2)
return TRUE;
if (!s1 || !s2)
return FALSE;
if (*s1 == *s2)
return TRUE;
if (!*s1 || !*s2)
return FALSE;
return **s1 == **s2;
}

View File

@@ -279,12 +279,20 @@ gboolean nm_pstr_equal (gconstpointer a, gconstpointer b);
/*****************************************************************************/
/* this hashes/compares the pointer value that we point to. Basically,
* (((const void *const*) a) == ((const void *const*) b)). */
* (*((const void *const*) a) == *((const void *const*) b)). */
guint nm_pdirect_hash (gconstpointer p);
gboolean nm_pdirect_equal (gconstpointer a, gconstpointer b);
/* this hashes/compares the direct pointer value by following pointers to
* pointers 2 times.
* (**((const void *const*const*) a) == **((const void *const*const*) b)). */
guint nm_ppdirect_hash (gconstpointer p);
gboolean nm_ppdirect_equal (gconstpointer a, gconstpointer b);
/*****************************************************************************/
#define NM_HASH_OBFUSCATE_PTR_FMT "%016" G_GINT64_MODIFIER "x"