mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-25 15:06:14 +01:00
Bug 580453 – Hash and equal functions for gint64 and gdouble
This commit is contained in:
parent
5a368d469a
commit
49dfb50afc
@ -2045,6 +2045,10 @@ g_direct_equal
|
||||
g_direct_hash
|
||||
g_int_equal
|
||||
g_int_hash
|
||||
g_int64_equal
|
||||
g_int64_hash
|
||||
g_double_equal
|
||||
g_double_hash
|
||||
g_str_equal
|
||||
g_str_hash
|
||||
|
||||
|
@ -432,6 +432,44 @@ with g_hash_table_iter_init().
|
||||
@Returns:
|
||||
|
||||
|
||||
<!-- ##### FUNCTION g_int64_equal ##### -->
|
||||
<para>
|
||||
|
||||
</para>
|
||||
|
||||
@v1:
|
||||
@v2:
|
||||
@Returns:
|
||||
|
||||
|
||||
<!-- ##### FUNCTION g_int64_hash ##### -->
|
||||
<para>
|
||||
|
||||
</para>
|
||||
|
||||
@v:
|
||||
@Returns:
|
||||
|
||||
|
||||
<!-- ##### FUNCTION g_double_equal ##### -->
|
||||
<para>
|
||||
|
||||
</para>
|
||||
|
||||
@v1:
|
||||
@v2:
|
||||
@Returns:
|
||||
|
||||
|
||||
<!-- ##### FUNCTION g_double_hash ##### -->
|
||||
<para>
|
||||
|
||||
</para>
|
||||
|
||||
@v:
|
||||
@Returns:
|
||||
|
||||
|
||||
<!-- ##### FUNCTION g_str_equal ##### -->
|
||||
<para>
|
||||
</para>
|
||||
|
13
glib/ghash.c
13
glib/ghash.c
@ -461,15 +461,16 @@ g_hash_table_maybe_resize (GHashTable *hash_table)
|
||||
* g_hash_table_new:
|
||||
* @hash_func: a function to create a hash value from a key.
|
||||
* Hash values are used to determine where keys are stored within the
|
||||
* #GHashTable data structure. The g_direct_hash(), g_int_hash() and
|
||||
* g_str_hash() functions are provided for some common types of keys.
|
||||
* #GHashTable data structure. The g_direct_hash(), g_int_hash(),
|
||||
* g_int64_hash(), g_double_hash() and g_str_hash() functions are provided
|
||||
* for some common types of keys.
|
||||
* If hash_func is %NULL, g_direct_hash() is used.
|
||||
* @key_equal_func: a function to check two keys for equality. This is
|
||||
* used when looking up keys in the #GHashTable. The g_direct_equal(),
|
||||
* g_int_equal() and g_str_equal() functions are provided for the most
|
||||
* common types of keys. If @key_equal_func is %NULL, keys are compared
|
||||
* directly in a similar fashion to g_direct_equal(), but without the
|
||||
* overhead of a function call.
|
||||
* g_int_equal(), g_int64_equal(), g_double_equal() and g_str_equal()
|
||||
* functions are provided for the most common types of keys.
|
||||
* If @key_equal_func is %NULL, keys are compared directly in a similar
|
||||
* fashion to g_direct_equal(), but without the overhead of a function call.
|
||||
*
|
||||
* Creates a new #GHashTable with a reference count of 1.
|
||||
*
|
||||
|
@ -130,6 +130,14 @@ gboolean g_int_equal (gconstpointer v1,
|
||||
gconstpointer v2);
|
||||
guint g_int_hash (gconstpointer v);
|
||||
|
||||
gboolean g_int64_equal (gconstpointer v1,
|
||||
gconstpointer v2);
|
||||
guint g_int64_hash (gconstpointer v);
|
||||
|
||||
gboolean g_double_equal (gconstpointer v1,
|
||||
gconstpointer v2);
|
||||
guint g_double_hash (gconstpointer v);
|
||||
|
||||
/* This "hash" function will just return the key's address as an
|
||||
* unsigned integer. Useful for hashing on plain addresses or
|
||||
* simple integer values.
|
||||
|
@ -1494,6 +1494,10 @@ glib_gettext G_GNUC_FORMAT(1)
|
||||
#if IN_FILE(__G_UTILS_C__)
|
||||
g_int_equal
|
||||
g_int_hash
|
||||
g_int64_equal
|
||||
g_int64_hash
|
||||
g_double_equal
|
||||
g_double_hash
|
||||
g_direct_equal G_GNUC_CONST
|
||||
g_direct_hash G_GNUC_CONST
|
||||
#endif
|
||||
|
@ -3195,6 +3195,84 @@ g_int_hash (gconstpointer v)
|
||||
return *(const gint*) v;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_int64_equal:
|
||||
* @v1: a pointer to a #gint64 key.
|
||||
* @v2: a pointer to a #gint64 key to compare with @v1.
|
||||
*
|
||||
* Compares the two #gint64 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 pointers to 64-bit integers as keys in a #GHashTable.
|
||||
*
|
||||
* Returns: %TRUE if the two keys match.
|
||||
*
|
||||
* Since: 2.22
|
||||
*/
|
||||
gboolean
|
||||
g_int64_equal (gconstpointer v1,
|
||||
gconstpointer v2)
|
||||
{
|
||||
return *((const gint64*) v1) == *((const gint64*) v2);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_int64_hash:
|
||||
* @v: a pointer to a #gint64 key
|
||||
*
|
||||
* Converts a pointer to a #gint64 to a hash value.
|
||||
* It can be passed to g_hash_table_new() as the @hash_func parameter,
|
||||
* when using pointers to 64-bit integers values as keys in a #GHashTable.
|
||||
*
|
||||
* Returns: a hash value corresponding to the key.
|
||||
*
|
||||
* Since: 2.22
|
||||
*/
|
||||
guint
|
||||
g_int64_hash (gconstpointer v)
|
||||
{
|
||||
return (guint) *(const gint64*) v;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_double_equal:
|
||||
* @v1: a pointer to a #gdouble key.
|
||||
* @v2: a pointer to a #gdouble key to compare with @v1.
|
||||
*
|
||||
* Compares the two #gdouble 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 pointers to doubles as keys in a #GHashTable.
|
||||
*
|
||||
* Returns: %TRUE if the two keys match.
|
||||
*
|
||||
* Since: 2.22
|
||||
*/
|
||||
gboolean
|
||||
g_double_equal (gconstpointer v1,
|
||||
gconstpointer v2)
|
||||
{
|
||||
return *((const gdouble*) v1) == *((const gdouble*) v2);
|
||||
}
|
||||
|
||||
/**
|
||||
* g_double_hash:
|
||||
* @v: a pointer to a #gdouble key
|
||||
*
|
||||
* Converts a pointer to a #gdouble to a hash value.
|
||||
* It can be passed to g_hash_table_new() as the @hash_func parameter,
|
||||
* when using pointers to doubles as keys in a #GHashTable.
|
||||
*
|
||||
* Returns: a hash value corresponding to the key.
|
||||
*
|
||||
* Since: 2.22
|
||||
*/
|
||||
guint
|
||||
g_double_hash (gconstpointer v)
|
||||
{
|
||||
return (guint) *(const gdouble*) v;
|
||||
}
|
||||
|
||||
/**
|
||||
* g_nullify_pointer:
|
||||
* @nullify_location: the memory address of the pointer.
|
||||
|
Loading…
Reference in New Issue
Block a user