+Fri Feb 20 03:02:05 2004 Tim Janik <timj@gtk.org>
+
+ * glib/ghash.[hc]: applied patch from #131937 with slight
+ renames. provides g_hash_table_find().
+
Fri Feb 20 02:39:03 2004 Tim Janik <timj@gtk.org>
* applied patch from David Schleef <ds@schleef.org> which implements
+Fri Feb 20 03:02:05 2004 Tim Janik <timj@gtk.org>
+
+ * glib/ghash.[hc]: applied patch from #131937 with slight
+ renames. provides g_hash_table_find().
+
Fri Feb 20 02:39:03 2004 Tim Janik <timj@gtk.org>
* applied patch from David Schleef <ds@schleef.org> which implements
+Fri Feb 20 03:02:05 2004 Tim Janik <timj@gtk.org>
+
+ * glib/ghash.[hc]: applied patch from #131937 with slight
+ renames. provides g_hash_table_find().
+
Fri Feb 20 02:39:03 2004 Tim Janik <timj@gtk.org>
* applied patch from David Schleef <ds@schleef.org> which implements
+Fri Feb 20 03:02:05 2004 Tim Janik <timj@gtk.org>
+
+ * glib/ghash.[hc]: applied patch from #131937 with slight
+ renames. provides g_hash_table_find().
+
Fri Feb 20 02:39:03 2004 Tim Janik <timj@gtk.org>
* applied patch from David Schleef <ds@schleef.org> which implements
+Fri Feb 20 03:02:05 2004 Tim Janik <timj@gtk.org>
+
+ * glib/ghash.[hc]: applied patch from #131937 with slight
+ renames. provides g_hash_table_find().
+
Fri Feb 20 02:39:03 2004 Tim Janik <timj@gtk.org>
* applied patch from David Schleef <ds@schleef.org> which implements
+Fri Feb 20 03:02:05 2004 Tim Janik <timj@gtk.org>
+
+ * glib/ghash.[hc]: applied patch from #131937 with slight
+ renames. provides g_hash_table_find().
+
Fri Feb 20 02:39:03 2004 Tim Janik <timj@gtk.org>
* applied patch from David Schleef <ds@schleef.org> which implements
separated by '_'.
@TYPE_PARENT: The #GType of the parent type.
@flags: #GTypeFlags to pass to g_type_register_static()
-@type_parent_class: the identifier for the static variable holding the parent class
@CODE: Custom code that gets inserted in the *_get_type() function.
@Since: 2.4
+<!-- # Unused Parameters # -->
+@type_parent_class: the identifier for the static variable holding the parent class
<!-- ##### MACRO G_TYPE_INVALID ##### -->
</para>
-<!-- ##### SIGNAL GObject::notify ##### -->
-<para>
-The notify signal is emitted on an object when one of its properties
-has been changed. Note that getting this signal doesn't guarantee that the
-value of the property has actually changed, it may also be emitted when
-the setter for the property is called to reinstate the previous value.
-</para>
-
-@gobject: the object which received the signal.
-@pspec: the #GParamSpec of the property which changed
-
<!-- ##### STRUCT GObjectClass ##### -->
<para>
The class structure for the <structname>GObject</structname> type.
@pspec: the #GParamSpec of the property
+<!-- ##### SIGNAL GObject::notify ##### -->
+<para>
+The notify signal is emitted on an object when one of its properties
+has been changed. Note that getting this signal doesn't guarantee that the
+value of the property has actually changed, it may also be emitted when
+the setter for the property is called to reinstate the previous value.
+</para>
+
+@gobject: the object which received the signal.
+@pspec: the #GParamSpec of the property which changed
+
(* func) (node->key, node->value, user_data);
}
+/**
+ * g_hash_table_find:
+ * @hash_table: a #GHashTable.
+ * @predicate: function to test the key/value pairs for a certain property.
+ * @user_data: user data to pass to the function.
+ *
+ * Calls the given function for key/value pairs in the
+ * #GHashTable until @predicate returns %TRUE. The function is passed
+ * the key and value of each pair, and the given @user_data parameter.
+ * The hash table may not
+ * be modified while iterating over it (you can't add/remove
+ * items).
+ * Return value: The value of the first key/value pair is returned, for which
+ * func evaluates to %TRUE. If no pair with the requested property is found,
+ * %NULL is returned
+ **/
+gpointer
+g_hash_table_find (GHashTable *hash_table,
+ GHRFunc predicate,
+ gpointer user_data)
+{
+ GHashNode *node;
+ gint i;
+
+ g_return_val_if_fail (hash_table != NULL, NULL);
+ g_return_val_if_fail (predicate != NULL, NULL);
+
+ for (i = 0; i < hash_table->size; i++)
+ for (node = hash_table->nodes[i]; node; node = node->next)
+ if (predicate (node->key, node->value, user_data))
+ return node->value;
+ return NULL;
+}
+
/**
* g_hash_table_size:
* @hash_table: a #GHashTable.
void g_hash_table_foreach (GHashTable *hash_table,
GHFunc func,
gpointer user_data);
+gpointer g_hash_table_find (GHashTable *hash_table,
+ GHRFunc predicate,
+ gpointer user_data);
guint g_hash_table_foreach_remove (GHashTable *hash_table,
GHRFunc func,
gpointer user_data);
g_hash_table_destroy (h);
}
+static gboolean find_first (gpointer key,
+ gpointer value,
+ gpointer user_data)
+{
+ gint *v = value;
+ gint *test = user_data;
+ return (*v == *test);
+}
+
static void direct_hash_test (void)
{
{
GHashTable *hash_table;
gint i;
-
+ gint value = 120;
+ gint *pvalue;
+
hash_table = g_hash_table_new (my_hash, my_hash_equal);
for (i = 0; i < 10000; i++)
{
array[i] = i;
g_hash_table_insert (hash_table, &array[i], &array[i]);
}
+ pvalue = g_hash_table_find (hash_table, find_first, &value);
+ if (!pvalue || *pvalue != value)
+ g_assert_not_reached();
+
g_hash_table_foreach (hash_table, my_hash_callback, NULL);
for (i = 0; i < 10000; i++)
return FALSE;
}
+static gboolean
+find_first_that(gpointer key,
+ gpointer value,
+ gpointer user_data)
+{
+ gint *v = value;
+ gint *test = user_data;
+ return (*v == *test);
+}
+
+
int
main (int argc,
char *argv[])
gint nums[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
gint morenums[10] = { 8, 9, 7, 0, 3, 2, 5, 1, 4, 6};
gchar *string;
-
+ gint value = 120;
+ gint *pvalue=NULL;
+
gchar *mem[10000], *tmp_string = NULL, *tmp_string_2;
gint i, j;
GArray *garray;
array[i] = i;
g_hash_table_insert (hash_table, &array[i], &array[i]);
}
+ pvalue = g_hash_table_find (hash_table, find_first_that, &value);
+ if (*pvalue != value)
+ g_print("g_hash_table_find failed");
+
g_hash_table_foreach (hash_table, my_hash_callback, NULL);
for (i = 0; i < 10000; i++)