libnm-glib-aux: add nm_puint64_hash()/nm_puint64_equal()

The two new functions can be used as GHashFunc and GEqualFunc when
creating hash tables whose keys are pointers to a guint64.
This commit is contained in:
Beniamino Galvani
2025-03-11 09:46:28 +01:00
parent 0e4330f2b4
commit 4ed1d04aff
2 changed files with 24 additions and 0 deletions

View File

@@ -190,6 +190,27 @@ nm_pint_equal(gconstpointer a, gconstpointer b)
return s1 == s2 || (s1 && s2 && *s1 == *s2);
}
/* GHashFunc for GHashTable keys that are a pointer to a guint64 */
guint
nm_puint64_hash(gconstpointer p)
{
const guint64 *s = p;
if (!s)
return nm_hash_static(298377461u);
return nm_hash_val(1208815757u, *s);
}
/* GEqualFunc for GHashTable keys that are a pointer to a guint64 */
gboolean
nm_puint64_equal(gconstpointer a, gconstpointer b)
{
const guint64 *s1 = a;
const guint64 *s2 = a;
return s1 == s2 || (s1 && s2 && *s1 == *s2);
}
guint
nm_pdirect_hash(gconstpointer p)
{

View File

@@ -266,6 +266,9 @@ gboolean nm_pstr_equal(gconstpointer a, gconstpointer b);
guint nm_pint_hash(gconstpointer p);
gboolean nm_pint_equal(gconstpointer a, gconstpointer b);
guint nm_puint64_hash(gconstpointer p);
gboolean nm_puint64_equal(gconstpointer a, gconstpointer b);
G_STATIC_ASSERT(sizeof(int) == sizeof(guint32));
#define nm_puint32_hash nm_pint_hash
#define nm_puint32_equal nm_pint_equal