mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-11-11 11:56:16 +01:00
Merge branch 'master' into 'master'
make g_tree_remove_all public See merge request GNOME/glib!1986
This commit is contained in:
commit
55cbc31517
@ -3055,6 +3055,7 @@ g_tree_lower_bound
|
|||||||
g_tree_upper_bound
|
g_tree_upper_bound
|
||||||
g_tree_remove
|
g_tree_remove
|
||||||
g_tree_steal
|
g_tree_steal
|
||||||
|
g_tree_remove_all
|
||||||
g_tree_destroy
|
g_tree_destroy
|
||||||
</SECTION>
|
</SECTION>
|
||||||
|
|
||||||
|
11
glib/gtree.c
11
glib/gtree.c
@ -338,7 +338,16 @@ g_tree_node_next (GTreeNode *node)
|
|||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
/**
|
||||||
|
* g_tree_remove_all:
|
||||||
|
* @tree: a #GTree
|
||||||
|
*
|
||||||
|
* Removes all nodes from a #GTree and destroys their keys and values,
|
||||||
|
* then resets the #GTree’s root to %NULL.
|
||||||
|
*
|
||||||
|
* Since: 2.70
|
||||||
|
*/
|
||||||
|
void
|
||||||
g_tree_remove_all (GTree *tree)
|
g_tree_remove_all (GTree *tree)
|
||||||
{
|
{
|
||||||
GTreeNode *node;
|
GTreeNode *node;
|
||||||
|
@ -111,6 +111,10 @@ void g_tree_replace (GTree *tree,
|
|||||||
GLIB_AVAILABLE_IN_ALL
|
GLIB_AVAILABLE_IN_ALL
|
||||||
gboolean g_tree_remove (GTree *tree,
|
gboolean g_tree_remove (GTree *tree,
|
||||||
gconstpointer key);
|
gconstpointer key);
|
||||||
|
|
||||||
|
GLIB_AVAILABLE_IN_2_70
|
||||||
|
void g_tree_remove_all (GTree *tree);
|
||||||
|
|
||||||
GLIB_AVAILABLE_IN_ALL
|
GLIB_AVAILABLE_IN_ALL
|
||||||
gboolean g_tree_steal (GTree *tree,
|
gboolean g_tree_steal (GTree *tree,
|
||||||
gconstpointer key);
|
gconstpointer key);
|
||||||
|
@ -68,17 +68,21 @@ my_search (gconstpointer a,
|
|||||||
|
|
||||||
static gpointer destroyed_key = NULL;
|
static gpointer destroyed_key = NULL;
|
||||||
static gpointer destroyed_value = NULL;
|
static gpointer destroyed_value = NULL;
|
||||||
|
static guint destroyed_key_count = 0;
|
||||||
|
static guint destroyed_value_count = 0;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
my_key_destroy (gpointer key)
|
my_key_destroy (gpointer key)
|
||||||
{
|
{
|
||||||
destroyed_key = key;
|
destroyed_key = key;
|
||||||
|
destroyed_key_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
my_value_destroy (gpointer value)
|
my_value_destroy (gpointer value)
|
||||||
{
|
{
|
||||||
destroyed_value = value;
|
destroyed_value = value;
|
||||||
|
destroyed_value_count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gint
|
static gint
|
||||||
@ -281,6 +285,32 @@ test_tree_remove (void)
|
|||||||
g_tree_destroy (tree);
|
g_tree_destroy (tree);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_tree_remove_all (void)
|
||||||
|
{
|
||||||
|
GTree *tree;
|
||||||
|
gsize i;
|
||||||
|
|
||||||
|
tree = g_tree_new_full ((GCompareDataFunc)my_compare, NULL,
|
||||||
|
my_key_destroy,
|
||||||
|
my_value_destroy);
|
||||||
|
|
||||||
|
for (i = 0; chars[i]; i++)
|
||||||
|
g_tree_insert (tree, &chars[i], &chars[i]);
|
||||||
|
|
||||||
|
destroyed_key_count = 0;
|
||||||
|
destroyed_value_count = 0;
|
||||||
|
|
||||||
|
g_tree_remove_all (tree);
|
||||||
|
|
||||||
|
g_assert_cmpuint (destroyed_key_count, ==, strlen (chars));
|
||||||
|
g_assert_cmpuint (destroyed_value_count, ==, strlen (chars));
|
||||||
|
g_assert_cmpint (g_tree_height (tree), ==, 0);
|
||||||
|
g_assert_cmpint (g_tree_nnodes (tree), ==, 0);
|
||||||
|
|
||||||
|
g_tree_unref (tree);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_tree_destroy (void)
|
test_tree_destroy (void)
|
||||||
{
|
{
|
||||||
@ -462,6 +492,7 @@ main (int argc, char *argv[])
|
|||||||
g_test_add_func ("/tree/destroy", test_tree_destroy);
|
g_test_add_func ("/tree/destroy", test_tree_destroy);
|
||||||
g_test_add_func ("/tree/traverse", test_tree_traverse);
|
g_test_add_func ("/tree/traverse", test_tree_traverse);
|
||||||
g_test_add_func ("/tree/insert", test_tree_insert);
|
g_test_add_func ("/tree/insert", test_tree_insert);
|
||||||
|
g_test_add_func ("/tree/remove-all", test_tree_remove_all);
|
||||||
|
|
||||||
return g_test_run ();
|
return g_test_run ();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user