summaryrefslogtreecommitdiff
path: root/testglib.c
diff options
context:
space:
mode:
authorManish Singh <yosh@src.gnome.org>1998-09-20 09:43:11 +0000
committerManish Singh <yosh@src.gnome.org>1998-09-20 09:43:11 +0000
commit034e7c0339f64d4d52a53f2324daa2fca0332add (patch)
tree0f4fed53778e5937ccc4bf92cfdc9fc7255973c5 /testglib.c
parenteeb971d1b95d5894bff1629c4c15a916646bc5d3 (diff)
downloadglib-034e7c0339f64d4d52a53f2324daa2fca0332add.tar.gz
This is Josh, commiting as Manish. This is completely new, and
nothing will break. * glib.h: New function g_hash_table_foreach_remove is similar to g_hash_table_foreach, but the callback's return value indicates whether to remove the element (if TRUE) or not (if FALSE).
Diffstat (limited to 'testglib.c')
-rw-r--r--testglib.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/testglib.c b/testglib.c
index d0440224d..1dd6efa80 100644
--- a/testglib.c
+++ b/testglib.c
@@ -177,6 +177,30 @@ g_node_test (void)
g_print ("ok\n");
}
+gboolean
+my_hash_callback_remove (gpointer key,
+ gpointer value,
+ gpointer user_data)
+{
+ int *d = value;
+
+ if ((*d) % 2)
+ return TRUE;
+
+ return FALSE;
+}
+
+void
+my_hash_callback_remove_test (gpointer key,
+ gpointer value,
+ gpointer user_data)
+{
+ int *d = value;
+
+ if ((*d) % 2)
+ g_print ("bad!\n");
+}
+
void
my_hash_callback (gpointer key,
gpointer value,
@@ -522,6 +546,19 @@ main (int argc,
for (i = 0; i < 10000; i++)
g_hash_table_remove (hash_table, &array[i]);
+ for (i = 0; i < 10000; i++)
+ {
+ array[i] = i;
+ g_hash_table_insert (hash_table, &array[i], &array[i]);
+ }
+
+ if (g_hash_table_foreach_remove (hash_table, my_hash_callback_remove, NULL) != 5000 ||
+ g_hash_table_size (hash_table) != 5000)
+ g_print ("bad!\n");
+
+ g_hash_table_foreach (hash_table, my_hash_callback_remove_test, NULL);
+
+
g_hash_table_destroy (hash_table);
g_print ("ok\n");