mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-07 19:35:50 +01:00
applied patch from #131937 with slight renames. provides
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().
This commit is contained in:
parent
b183ffc5ed
commit
ee4e622d37
@ -1,3 +1,8 @@
|
|||||||
|
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>
|
Fri Feb 20 02:39:03 2004 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
* applied patch from David Schleef <ds@schleef.org> which implements
|
* applied patch from David Schleef <ds@schleef.org> which implements
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
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>
|
Fri Feb 20 02:39:03 2004 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
* applied patch from David Schleef <ds@schleef.org> which implements
|
* applied patch from David Schleef <ds@schleef.org> which implements
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
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>
|
Fri Feb 20 02:39:03 2004 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
* applied patch from David Schleef <ds@schleef.org> which implements
|
* applied patch from David Schleef <ds@schleef.org> which implements
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
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>
|
Fri Feb 20 02:39:03 2004 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
* applied patch from David Schleef <ds@schleef.org> which implements
|
* applied patch from David Schleef <ds@schleef.org> which implements
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
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>
|
Fri Feb 20 02:39:03 2004 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
* applied patch from David Schleef <ds@schleef.org> which implements
|
* applied patch from David Schleef <ds@schleef.org> which implements
|
||||||
|
@ -1,3 +1,8 @@
|
|||||||
|
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>
|
Fri Feb 20 02:39:03 2004 Tim Janik <timj@gtk.org>
|
||||||
|
|
||||||
* applied patch from David Schleef <ds@schleef.org> which implements
|
* applied patch from David Schleef <ds@schleef.org> which implements
|
||||||
|
@ -1619,9 +1619,10 @@ init functions.
|
|||||||
separated by '_'.
|
separated by '_'.
|
||||||
@TYPE_PARENT: The #GType of the parent type.
|
@TYPE_PARENT: The #GType of the parent type.
|
||||||
@flags: #GTypeFlags to pass to g_type_register_static()
|
@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.
|
@CODE: Custom code that gets inserted in the *_get_type() function.
|
||||||
@Since: 2.4
|
@Since: 2.4
|
||||||
|
<!-- # Unused Parameters # -->
|
||||||
|
@type_parent_class: the identifier for the static variable holding the parent class
|
||||||
|
|
||||||
|
|
||||||
<!-- ##### MACRO G_TYPE_INVALID ##### -->
|
<!-- ##### MACRO G_TYPE_INVALID ##### -->
|
||||||
|
@ -21,17 +21,6 @@ to the #GObject implementation and should never be accessed directly.
|
|||||||
</para>
|
</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 ##### -->
|
<!-- ##### STRUCT GObjectClass ##### -->
|
||||||
<para>
|
<para>
|
||||||
The class structure for the <structname>GObject</structname> type.
|
The class structure for the <structname>GObject</structname> type.
|
||||||
@ -866,3 +855,14 @@ properties in set_property() and get_property() implementations.
|
|||||||
@pspec: the #GParamSpec of the property
|
@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
|
||||||
|
|
||||||
|
34
glib/ghash.c
34
glib/ghash.c
@ -559,6 +559,40 @@ g_hash_table_foreach (GHashTable *hash_table,
|
|||||||
(* func) (node->key, node->value, user_data);
|
(* 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:
|
* g_hash_table_size:
|
||||||
* @hash_table: a #GHashTable.
|
* @hash_table: a #GHashTable.
|
||||||
|
@ -65,6 +65,9 @@ gboolean g_hash_table_lookup_extended (GHashTable *hash_table,
|
|||||||
void g_hash_table_foreach (GHashTable *hash_table,
|
void g_hash_table_foreach (GHashTable *hash_table,
|
||||||
GHFunc func,
|
GHFunc func,
|
||||||
gpointer user_data);
|
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,
|
guint g_hash_table_foreach_remove (GHashTable *hash_table,
|
||||||
GHRFunc func,
|
GHRFunc func,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
|
@ -296,6 +296,15 @@ static void second_hash_test (gboolean simple_hash)
|
|||||||
g_hash_table_destroy (h);
|
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)
|
static void direct_hash_test (void)
|
||||||
{
|
{
|
||||||
@ -332,13 +341,19 @@ main (int argc,
|
|||||||
{
|
{
|
||||||
GHashTable *hash_table;
|
GHashTable *hash_table;
|
||||||
gint i;
|
gint i;
|
||||||
|
gint value = 120;
|
||||||
|
gint *pvalue;
|
||||||
|
|
||||||
hash_table = g_hash_table_new (my_hash, my_hash_equal);
|
hash_table = g_hash_table_new (my_hash, my_hash_equal);
|
||||||
for (i = 0; i < 10000; i++)
|
for (i = 0; i < 10000; i++)
|
||||||
{
|
{
|
||||||
array[i] = i;
|
array[i] = i;
|
||||||
g_hash_table_insert (hash_table, &array[i], &array[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);
|
g_hash_table_foreach (hash_table, my_hash_callback, NULL);
|
||||||
|
|
||||||
for (i = 0; i < 10000; i++)
|
for (i = 0; i < 10000; i++)
|
||||||
|
@ -307,6 +307,17 @@ my_traverse (gpointer key,
|
|||||||
return FALSE;
|
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
|
int
|
||||||
main (int argc,
|
main (int argc,
|
||||||
char *argv[])
|
char *argv[])
|
||||||
@ -320,7 +331,9 @@ main (int argc,
|
|||||||
gint nums[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
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};
|
gint morenums[10] = { 8, 9, 7, 0, 3, 2, 5, 1, 4, 6};
|
||||||
gchar *string;
|
gchar *string;
|
||||||
|
gint value = 120;
|
||||||
|
gint *pvalue=NULL;
|
||||||
|
|
||||||
gchar *mem[10000], *tmp_string = NULL, *tmp_string_2;
|
gchar *mem[10000], *tmp_string = NULL, *tmp_string_2;
|
||||||
gint i, j;
|
gint i, j;
|
||||||
GArray *garray;
|
GArray *garray;
|
||||||
@ -720,6 +733,10 @@ main (int argc,
|
|||||||
array[i] = i;
|
array[i] = i;
|
||||||
g_hash_table_insert (hash_table, &array[i], &array[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);
|
g_hash_table_foreach (hash_table, my_hash_callback, NULL);
|
||||||
|
|
||||||
for (i = 0; i < 10000; i++)
|
for (i = 0; i < 10000; i++)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user