diff options
author | Thomas Haller <thaller@redhat.com> | 2019-10-27 09:23:39 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2019-11-07 11:34:36 +0100 |
commit | d21439eaa0f80512dce211c9b2bc9032e0873820 (patch) | |
tree | 0536b51f5111f63263ba39957af83decf891100a | |
parent | 86352ceaf854e6861d370adb28f878c6c746fabb (diff) | |
download | NetworkManager-d21439eaa0f80512dce211c9b2bc9032e0873820.tar.gz |
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.
-rw-r--r-- | shared/nm-glib-aux/nm-hash-utils.c | 31 | ||||
-rw-r--r-- | shared/nm-glib-aux/nm-hash-utils.h | 10 |
2 files changed, 40 insertions, 1 deletions
diff --git a/shared/nm-glib-aux/nm-hash-utils.c b/shared/nm-glib-aux/nm-hash-utils.c index 8fef015f8b..a821259815 100644 --- a/shared/nm-glib-aux/nm-hash-utils.c +++ b/shared/nm-glib-aux/nm-hash-utils.c @@ -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; +} diff --git a/shared/nm-glib-aux/nm-hash-utils.h b/shared/nm-glib-aux/nm-hash-utils.h index 2e7b35183f..c95cc6db91 100644 --- a/shared/nm-glib-aux/nm-hash-utils.h +++ b/shared/nm-glib-aux/nm-hash-utils.h @@ -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" |