Bug 580453 – Hash and equal functions for gint64 and gdouble
authorDavid Zeuthen <davidz@redhat.com>
Sun, 26 Apr 2009 02:41:07 +0000 (22:41 -0400)
committerDavid Zeuthen <davidz@redhat.com>
Mon, 27 Apr 2009 17:27:44 +0000 (13:27 -0400)
docs/reference/glib/glib-sections.txt
docs/reference/glib/tmpl/hash_tables.sgml
glib/ghash.c
glib/ghash.h
glib/glib.symbols
glib/gutils.c

index 4feea78..85335af 100644 (file)
@@ -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
 
index 40ece8d..2fa2c86 100644 (file)
@@ -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>
index ba33266..820d095 100644 (file)
@@ -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.
  *
index afdd072..7f1e79e 100644 (file)
@@ -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.
index 082aed5..ce6a148 100644 (file)
@@ -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
index 858603b..148d655 100644 (file)
@@ -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.
  *