summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2019-11-07 15:17:39 +0100
committerThomas Haller <thaller@redhat.com>2019-11-25 12:58:33 +0100
commitbc9baf0fd5d77fdee17a88f2eeffda1ef241e012 (patch)
tree9a6dc4b0940264b0cdb69b85a1827aef0fa0905f
parentd0f385ce343e4cbe9d9e45be785361efadb3c292 (diff)
downloadNetworkManager-bc9baf0fd5d77fdee17a88f2eeffda1ef241e012.tar.gz
shared: add nm_pint_hash()/nm_pint_equals() utils
-rw-r--r--shared/nm-glib-aux/nm-hash-utils.c20
-rw-r--r--shared/nm-glib-aux/nm-hash-utils.h8
2 files changed, 28 insertions, 0 deletions
diff --git a/shared/nm-glib-aux/nm-hash-utils.c b/shared/nm-glib-aux/nm-hash-utils.c
index a821259815..cd51bbaf63 100644
--- a/shared/nm-glib-aux/nm-hash-utils.c
+++ b/shared/nm-glib-aux/nm-hash-utils.c
@@ -186,6 +186,26 @@ nm_pstr_equal (gconstpointer a, gconstpointer b)
}
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
nm_pdirect_hash (gconstpointer p)
{
const void *const*s = p;
diff --git a/shared/nm-glib-aux/nm-hash-utils.h b/shared/nm-glib-aux/nm-hash-utils.h
index c95cc6db91..21c5e58416 100644
--- a/shared/nm-glib-aux/nm-hash-utils.h
+++ b/shared/nm-glib-aux/nm-hash-utils.h
@@ -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,
* (*((const void *const*) a) == *((const void *const*) b)). */