summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-03-20 22:47:40 +0100
committerThomas Haller <thaller@redhat.com>2020-04-02 11:58:28 +0200
commit0f2472316b887a8365e916e419c441ba62793a7b (patch)
treed3c48c8330951cbfb7359cff22a20778bc0c9174
parentfa36f883a1c2cb5c035420c9fb90ca898d5ba87b (diff)
downloadNetworkManager-0f2472316b887a8365e916e419c441ba62793a7b.tar.gz
shared: add nm_pgbytes_hash()/nm_pgbytes_equal()
For hashing of a pointer to a GBytes*. This is useful if your key is a GBytes array, and the first field in your to be hashed struct.
-rw-r--r--shared/nm-glib-aux/nm-hash-utils.c22
-rw-r--r--shared/nm-glib-aux/nm-hash-utils.h5
2 files changed, 27 insertions, 0 deletions
diff --git a/shared/nm-glib-aux/nm-hash-utils.c b/shared/nm-glib-aux/nm-hash-utils.c
index cd51bbaf63..dcf662053a 100644
--- a/shared/nm-glib-aux/nm-hash-utils.c
+++ b/shared/nm-glib-aux/nm-hash-utils.c
@@ -257,3 +257,25 @@ nm_ppdirect_equal (gconstpointer a, gconstpointer b)
return **s1 == **s2;
}
+
+/*****************************************************************************/
+
+guint
+nm_pgbytes_hash (gconstpointer p)
+{
+ GBytes *const*ptr = p;
+ gconstpointer arr;
+ gsize len;
+
+ arr = g_bytes_get_data (*ptr, &len);
+ return nm_hash_mem (1470631313u, arr, len);
+}
+
+gboolean
+nm_pgbytes_equal (gconstpointer a, gconstpointer b)
+{
+ GBytes *const*ptr_a = a;
+ GBytes *const*ptr_b = b;
+
+ return g_bytes_equal (*ptr_a, *ptr_b);
+}
diff --git a/shared/nm-glib-aux/nm-hash-utils.h b/shared/nm-glib-aux/nm-hash-utils.h
index 1f29413bd9..9879dc477b 100644
--- a/shared/nm-glib-aux/nm-hash-utils.h
+++ b/shared/nm-glib-aux/nm-hash-utils.h
@@ -314,6 +314,11 @@ gboolean nm_ppdirect_equal (gconstpointer a, gconstpointer b);
/*****************************************************************************/
+guint nm_pgbytes_hash (gconstpointer p);
+gboolean nm_pgbytes_equal (gconstpointer a, gconstpointer b);
+
+/*****************************************************************************/
+
#define NM_HASH_OBFUSCATE_PTR_FMT "%016" G_GINT64_MODIFIER "x"
/* sometimes we want to log a pointer directly, for providing context/information about