[glib] Bug 580453 – Hash and equal functions for gint64 and gdouble
- From: David Zeuthen <davidz src gnome org>
- To: svn-commits-list gnome org
- Subject: [glib] Bug 580453 – Hash and equal functions for gint64 and gdouble
- Date: Mon, 27 Apr 2009 13:30:34 -0400 (EDT)
commit 49dfb50afc9400779c0be02ea3c285780b42c928
Author: David Zeuthen <davidz redhat com>
Date: Sat Apr 25 22:41:07 2009 -0400
Bug 580453 â?? Hash and equal functions for gint64 and gdouble
---
docs/reference/glib/glib-sections.txt | 4 ++
docs/reference/glib/tmpl/hash_tables.sgml | 38 ++++++++++++++
glib/ghash.c | 13 +++--
glib/ghash.h | 8 +++
glib/glib.symbols | 4 ++
glib/gutils.c | 78 +++++++++++++++++++++++++++++
6 files changed, 139 insertions(+), 6 deletions(-)
diff --git a/docs/reference/glib/glib-sections.txt b/docs/reference/glib/glib-sections.txt
index 4feea78..85335af 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 40ece8d..2fa2c86 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:
+<!-- ##### 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>
diff --git a/glib/ghash.c b/glib/ghash.c
index ba33266..820d095 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 afdd072..7f1e79e 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 082aed5..ce6a148 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 858603b..148d655 100644
--- a/glib/gutils.c
+++ b/glib/gutils.c
@@ -3196,6 +3196,84 @@ g_int_hash (gconstpointer 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.
*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]