From: Tim Janik Date: Fri, 20 Feb 2004 02:05:36 +0000 (+0000) Subject: applied patch from #131937 with slight renames. provides X-Git-Tag: GLIB_2_3_3~10 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ee4e622d3724a6dfee8ce9463eccb31081cf852f;p=platform%2Fupstream%2Fglib.git applied patch from #131937 with slight renames. provides Fri Feb 20 03:02:05 2004 Tim Janik * glib/ghash.[hc]: applied patch from #131937 with slight renames. provides g_hash_table_find(). --- diff --git a/ChangeLog b/ChangeLog index 2304e4914..31aa3438f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Fri Feb 20 03:02:05 2004 Tim Janik + + * glib/ghash.[hc]: applied patch from #131937 with slight + renames. provides g_hash_table_find(). + Fri Feb 20 02:39:03 2004 Tim Janik * applied patch from David Schleef which implements diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 2304e4914..31aa3438f 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,8 @@ +Fri Feb 20 03:02:05 2004 Tim Janik + + * glib/ghash.[hc]: applied patch from #131937 with slight + renames. provides g_hash_table_find(). + Fri Feb 20 02:39:03 2004 Tim Janik * applied patch from David Schleef which implements diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index 2304e4914..31aa3438f 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,8 @@ +Fri Feb 20 03:02:05 2004 Tim Janik + + * glib/ghash.[hc]: applied patch from #131937 with slight + renames. provides g_hash_table_find(). + Fri Feb 20 02:39:03 2004 Tim Janik * applied patch from David Schleef which implements diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 2304e4914..31aa3438f 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,8 @@ +Fri Feb 20 03:02:05 2004 Tim Janik + + * glib/ghash.[hc]: applied patch from #131937 with slight + renames. provides g_hash_table_find(). + Fri Feb 20 02:39:03 2004 Tim Janik * applied patch from David Schleef which implements diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 2304e4914..31aa3438f 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,8 @@ +Fri Feb 20 03:02:05 2004 Tim Janik + + * glib/ghash.[hc]: applied patch from #131937 with slight + renames. provides g_hash_table_find(). + Fri Feb 20 02:39:03 2004 Tim Janik * applied patch from David Schleef which implements diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 2304e4914..31aa3438f 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,8 @@ +Fri Feb 20 03:02:05 2004 Tim Janik + + * glib/ghash.[hc]: applied patch from #131937 with slight + renames. provides g_hash_table_find(). + Fri Feb 20 02:39:03 2004 Tim Janik * applied patch from David Schleef which implements diff --git a/docs/reference/gobject/tmpl/gtype.sgml b/docs/reference/gobject/tmpl/gtype.sgml index 2d5416258..79a70a3a5 100644 --- a/docs/reference/gobject/tmpl/gtype.sgml +++ b/docs/reference/gobject/tmpl/gtype.sgml @@ -1619,9 +1619,10 @@ init functions. 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 + +@type_parent_class: the identifier for the static variable holding the parent class diff --git a/docs/reference/gobject/tmpl/objects.sgml b/docs/reference/gobject/tmpl/objects.sgml index 2d16e5d2c..4c311e911 100644 --- a/docs/reference/gobject/tmpl/objects.sgml +++ b/docs/reference/gobject/tmpl/objects.sgml @@ -21,17 +21,6 @@ to the #GObject implementation and should never be accessed directly. - - -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. - - -@gobject: the object which received the signal. -@pspec: the #GParamSpec of the property which changed - The class structure for the GObject type. @@ -866,3 +855,14 @@ properties in set_property() and get_property() implementations. @pspec: the #GParamSpec of the property + + +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. + + +@gobject: the object which received the signal. +@pspec: the #GParamSpec of the property which changed + diff --git a/glib/ghash.c b/glib/ghash.c index a2653f333..a909db948 100644 --- a/glib/ghash.c +++ b/glib/ghash.c @@ -559,6 +559,40 @@ g_hash_table_foreach (GHashTable *hash_table, (* 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. diff --git a/glib/ghash.h b/glib/ghash.h index a3051218e..f0886d5c0 100644 --- a/glib/ghash.h +++ b/glib/ghash.h @@ -65,6 +65,9 @@ gboolean g_hash_table_lookup_extended (GHashTable *hash_table, 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); diff --git a/tests/hash-test.c b/tests/hash-test.c index 95d144fab..00074fb1b 100644 --- a/tests/hash-test.c +++ b/tests/hash-test.c @@ -296,6 +296,15 @@ static void second_hash_test (gboolean simple_hash) 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) { @@ -332,13 +341,19 @@ main (int argc, { 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++) diff --git a/tests/testglib.c b/tests/testglib.c index bc807a422..d0bd7bb14 100644 --- a/tests/testglib.c +++ b/tests/testglib.c @@ -307,6 +307,17 @@ my_traverse (gpointer key, 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[]) @@ -320,7 +331,9 @@ main (int argc, 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; @@ -720,6 +733,10 @@ main (int argc, 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++)