mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-25 00:10:07 +01:00
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.
This commit is contained in:
parent
b1503d8a72
commit
573b02f7d7
2 changed files with 27 additions and 0 deletions
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue