mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-09 12:25:48 +01:00
glib: add internal g_uint_hash()/g_uint_equal()
We have g_int_hash()/g_int_equal(), which in practice might also work with with pointers to unsigned integers. However, according to strict interpretation of C, I think it is not valid to conflate the two. Even if it were valid in all cases that we want to support, we should still have separate g_uint_{hash,equal} functions (e.g. by just #define them to their underlying g_int_{hash,equal} implementations). Add instead internal hash/equal functions for guint.
This commit is contained in:
parent
734f8184e8
commit
3c09257ea1
44
glib/ghash.c
44
glib/ghash.c
@ -2552,6 +2552,50 @@ g_int_hash (gconstpointer v)
|
|||||||
return *(const gint*) v;
|
return *(const gint*) v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* g_uint_equal:
|
||||||
|
* @v1: (not nullable): a pointer to a #guint key
|
||||||
|
* @v2: (not nullable): a pointer to a #guint key to compare with @v1
|
||||||
|
*
|
||||||
|
* Compares the two #guint values being pointed to and returns
|
||||||
|
* %TRUE if they are equal.
|
||||||
|
* It can be passed to g_hash_table_new() as the @key_equal_func
|
||||||
|
* parameter, when using non-%NULL pointers to integers as keys in a
|
||||||
|
* #GHashTable.
|
||||||
|
*
|
||||||
|
* Note that this function acts on pointers to #guint, not on #guint
|
||||||
|
* directly: if your hash table's keys are of the form
|
||||||
|
* `GUINT_TO_POINTER (n)`, use g_direct_equal() instead.
|
||||||
|
*
|
||||||
|
* Returns: %TRUE if the two keys match.
|
||||||
|
*/
|
||||||
|
gboolean
|
||||||
|
g_uint_equal (gconstpointer v1,
|
||||||
|
gconstpointer v2)
|
||||||
|
{
|
||||||
|
return *((const guint *) v1) == *((const guint *) v2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* g_uint_hash:
|
||||||
|
* @v: (not nullable): a pointer to a #guint key
|
||||||
|
*
|
||||||
|
* Converts a pointer to a #guint to a hash value.
|
||||||
|
* It can be passed to g_hash_table_new() as the @hash_func parameter,
|
||||||
|
* when using non-%NULL pointers to integer values as keys in a #GHashTable.
|
||||||
|
*
|
||||||
|
* Note that this function acts on pointers to #guint, not on #guint
|
||||||
|
* directly: if your hash table's keys are of the form
|
||||||
|
* `GUINT_TO_POINTER (n)`, use g_direct_hash() instead.
|
||||||
|
*
|
||||||
|
* Returns: a hash value corresponding to the key.
|
||||||
|
*/
|
||||||
|
guint
|
||||||
|
g_uint_hash (gconstpointer v)
|
||||||
|
{
|
||||||
|
return *(const guint *) v;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* g_int64_equal:
|
* g_int64_equal:
|
||||||
* @v1: (not nullable): a pointer to a #gint64 key
|
* @v1: (not nullable): a pointer to a #gint64 key
|
||||||
|
@ -303,4 +303,7 @@ GLibPrivateVTable *glib__private__ (void);
|
|||||||
# define GLIB_DEFAULT_LOCALE ""
|
# define GLIB_DEFAULT_LOCALE ""
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
gboolean g_uint_equal (gconstpointer v1, gconstpointer v2);
|
||||||
|
guint g_uint_hash (gconstpointer v);
|
||||||
|
|
||||||
#endif /* __GLIB_PRIVATE_H__ */
|
#endif /* __GLIB_PRIVATE_H__ */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user