typedef typedefG_BEGIN_DECLS struct _GTree | GTree |
typedef gboolean(* | GTraverseFunc |
IMPORT_C GTree * | g_tree_new | ( | GCompareFunc | key_compare_func | ) |
g_tree_new: : the function used to order the nodes in the GTree. It should return values similar to the standard strcmp() function - 0 if the two arguments are equal, a negative value if the first argument comes before the second, or a positive value if the first argument comes after the second.
Creates a new GTree.
Return value: a new GTree.
IMPORT_C GTree * | g_tree_new_with_data | ( | GCompareDataFunc | key_compare_func, |
gpointer | key_compare_data | |||
) |
g_tree_new_with_data: : qsort()-style comparison function. : data to pass to comparison function.
Creates a new GTree with a comparison function that accepts user data. See g_tree_new() for more details.
Return value: a new GTree.
IMPORT_C GTree * | g_tree_new_full | ( | GCompareDataFunc | key_compare_func, |
gpointer | key_compare_data, | |||
GDestroyNotify | key_destroy_func, | |||
GDestroyNotify | value_destroy_func | |||
) |
g_tree_new_full: : qsort()-style comparison function. : data to pass to comparison function. : a function to free the memory allocated for the key used when removing the entry from the GTree or NULL if you don't want to supply such a function. : a function to free the memory allocated for the value used when removing the entry from the GTree or NULL if you don't want to supply such a function.
Creates a new GTree like g_tree_new() and allows to specify functions to free the memory allocated for the key and value that get called when removing the entry from the GTree.
Return value: a new GTree.
IMPORT_C void | g_tree_destroy | ( | GTree * | tree | ) |
g_tree_destroy: : a GTree.
Destroys the GTree. If keys and/or values are dynamically allocated, you should either free them first or create the GTree using g_tree_new_full(). In the latter case the destroy functions you supplied will be called on all keys and values before destroying the GTree.
g_tree_insert: : a GTree. : the key to insert. : the value corresponding to the key.
Inserts a key/value pair into a GTree. If the given key already exists in the GTree its corresponding value is set to the new value. If you supplied a value_destroy_func when creating the GTree, the old value is freed using that function. If you supplied a when creating the GTree, the passed key is freed using that function.
The tree is automatically 'balanced' as new key/value pairs are added, so that the distance from the root to every leaf is as small as possible.
g_tree_replace: : a GTree. : the key to insert. : the value corresponding to the key.
Inserts a new key and value into a GTree similar to g_tree_insert(). The difference is that if the key already exists in the GTree, it gets replaced by the new key. If you supplied a when creating the GTree, the old value is freed using that function. If you supplied a when creating the GTree, the old key is freed using that function.
The tree is automatically 'balanced' as new key/value pairs are added, so that the distance from the root to every leaf is as small as possible.
IMPORT_C gboolean | g_tree_remove | ( | GTree * | tree, |
gconstpointer | key | |||
) |
g_tree_remove: : a GTree. : the key to remove.
Removes a key/value pair from a GTree.
If the GTree was created using g_tree_new_full(), the key and value are freed using the supplied destroy functions, otherwise you have to make sure that any dynamically allocated values are freed yourself. If the key does not exist in the GTree, the function does nothing.
Returns: TRUE if the key was found (prior to 2.8, this function returned nothing)
IMPORT_C gboolean | g_tree_steal | ( | GTree * | tree, |
gconstpointer | key | |||
) |
g_tree_steal: : a GTree. : the key to remove.
Removes a key and its associated value from a GTree without calling the key and value destroy functions.
If the key does not exist in the GTree, the function does nothing.
Returns: TRUE if the key was found (prior to 2.8, this function returned nothing)
IMPORT_C gpointer | g_tree_lookup | ( | GTree * | tree, |
gconstpointer | key | |||
) |
g_tree_lookup: : a GTree. : the key to look up.
Gets the value corresponding to the given key. Since a GTree is automatically balanced as key/value pairs are added, key lookup is very fast.
Return value: the value corresponding to the key, or NULL if the key was not found.
IMPORT_C gboolean | g_tree_lookup_extended | ( | GTree * | tree, |
gconstpointer | lookup_key, | |||
gpointer * | orig_key, | |||
gpointer * | value | |||
) |
g_tree_lookup_extended: : a GTree. : the key to look up. : returns the original key. : returns the value associated with the key.
Looks up a key in the GTree, returning the original key and the associated value and a gboolean which is TRUE if the key was found. This is useful if you need to free the memory allocated for the original key, for example before calling g_tree_remove().
Return value: TRUE if the key was found in the GTree.
IMPORT_C void | g_tree_foreach | ( | GTree * | tree, |
GTraverseFunc | func, | |||
gpointer | user_data | |||
) |
g_tree_foreach: : a GTree. : the function to call for each node visited. If this function returns TRUE, the traversal is stopped. : user data to pass to the function.
Calls the given function for each of the key/value pairs in the GTree. The function is passed the key and value of each pair, and the given parameter. The tree is traversed in sorted order.
The tree may not be modified while iterating over it (you can't add/remove items). To remove all items matching a predicate, you need to add each item to a list in your GTraverseFunc as you walk over the tree, then walk the list and remove each item.
IMPORT_C void | g_tree_traverse | ( | GTree * | tree, |
GTraverseFunc | traverse_func, | |||
GTraverseType | traverse_type, | |||
gpointer | user_data | |||
) |
g_tree_traverse: : a GTree. : the function to call for each node visited. If this function returns TRUE, the traversal is stopped. : the order in which nodes are visited, one of G_IN_ORDER, G_PRE_ORDER and G_POST_ORDER. : user data to pass to the function.
Calls the given function for each node in the GTree.
Deprecated:2.2: The order of a balanced tree is somewhat arbitrary. If you just want to visit all nodes in sorted order, use g_tree_foreach() instead. If you really need to visit nodes in a different order, consider using an <link linkend="glib-N-ary-Trees">N-ary Tree</link>.
IMPORT_C gpointer | g_tree_search | ( | GTree * | tree, |
GCompareFunc | search_func, | |||
gconstpointer | user_data | |||
) |
g_tree_search: : a GTree. : a function used to search the GTree. : the data passed as the second argument to the function.
Searches a GTree using .
The is called with a pointer to the key of a key/value pair in the tree, and the passed in . If returns 0 for a key/value pair, then g_tree_search_func() will return the value of that pair. If returns -1, searching will proceed among the key/value pairs that have a smaller key; if returns 1, searching will proceed among the key/value pairs that have a larger key.
Return value: the value corresponding to the found key, or NULL if the key was not found.