shared: add nm_pint_hash()/nm_pint_equals() utils

This commit is contained in:
Thomas Haller
2019-11-07 15:17:39 +01:00
parent d0f385ce34
commit bc9baf0fd5
2 changed files with 28 additions and 0 deletions

View File

@@ -185,6 +185,26 @@ nm_pstr_equal (gconstpointer a, gconstpointer b)
&& nm_streq0 (*s1, *s2)); && nm_streq0 (*s1, *s2));
} }
guint
nm_pint_hash (gconstpointer p)
{
const int *s = p;
if (!s)
return nm_hash_static (298377461u);
return nm_hash_val (1208815757u, *s);
}
gboolean
nm_pint_equals (gconstpointer a, gconstpointer b)
{
const int *s1 = a;
const int *s2 = a;
return s1 == s2
|| (s1 && s2 && *s1 == *s2);
}
guint guint
nm_pdirect_hash (gconstpointer p) nm_pdirect_hash (gconstpointer p)
{ {

View File

@@ -278,6 +278,14 @@ gboolean nm_pstr_equal (gconstpointer a, gconstpointer b);
/*****************************************************************************/ /*****************************************************************************/
/* nm_pint_*() are for hashing keys that are pointers to int values,
* that is, "const int *" types. */
guint nm_pint_hash (gconstpointer p);
gboolean nm_pint_equals (gconstpointer a, gconstpointer b);
/*****************************************************************************/
/* this hashes/compares the pointer value that we point to. Basically, /* 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)). */