From: David Zeuthen Date: Sun, 26 Apr 2009 02:41:07 +0000 (-0400) Subject: Bug 580453 – Hash and equal functions for gint64 and gdouble X-Git-Url: http://git.openbox.org/?a=commitdiff_plain;h=49dfb50afc9400779c0be02ea3c285780b42c928;p=dana%2Fcg-glib.git Bug 580453 – Hash and equal functions for gint64 and gdouble --- diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt index 4feea780..85335afd 100644 --- a/docs/reference/glib/glib-sections.txt +++ b/docs/reference/glib/glib-sections.txt @@ -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 diff --git a/docs/reference/glib/tmpl/hash_tables.sgml b/docs/reference/glib/tmpl/hash_tables.sgml index 40ece8d9..2fa2c86c 100644 --- a/docs/reference/glib/tmpl/hash_tables.sgml +++ b/docs/reference/glib/tmpl/hash_tables.sgml @@ -432,6 +432,44 @@ with g_hash_table_iter_init(). @Returns: + + + + + +@v1: +@v2: +@Returns: + + + + + + + +@v: +@Returns: + + + + + + + +@v1: +@v2: +@Returns: + + + + + + + +@v: +@Returns: + + diff --git a/glib/ghash.c b/glib/ghash.c index ba332669..820d0954 100644 --- a/glib/ghash.c +++ b/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. * diff --git a/glib/ghash.h b/glib/ghash.h index afdd0729..7f1e79e1 100644 --- a/glib/ghash.h +++ b/glib/ghash.h @@ -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. diff --git a/glib/glib.symbols b/glib/glib.symbols index 082aed51..ce6a148f 100644 --- a/glib/glib.symbols +++ b/glib/glib.symbols @@ -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 diff --git a/glib/gutils.c b/glib/gutils.c index 858603b8..148d655a 100644 --- a/glib/gutils.c +++ b/glib/gutils.c @@ -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.