blob: 0c570d08b4f164d74db2460ca010e3de6256277b [file] [log] [blame]
<!-- ##### SECTION Title ##### -->
N-ary Trees
<!-- ##### SECTION Short_Description ##### -->
trees of data with any number of branches
<!-- ##### SECTION Long_Description ##### -->
<para>
The #GNode struct and its associated functions provide a N-ary tree data
structure, where nodes in the tree can contain arbitrary data.
</para>
<para>
To create a new tree use g_node_new().
</para>
<para>
To insert a node into a tree use g_node_insert(), g_node_insert_before(),
g_node_append() and g_node_prepend().
</para>
<para>
To create a new node and insert it into a tree use g_node_insert_data(),
g_node_insert_data_before(), g_node_append_data() and g_node_prepend_data().
</para>
<para>
To reverse the children of a node use g_node_reverse_children().
</para>
<para>
To find a node use g_node_get_root(), g_node_find(), g_node_find_child(),
g_node_child_index(), g_node_child_position(),
g_node_first_child(), g_node_last_child(),
g_node_nth_child(), g_node_first_sibling(), g_node_prev_sibling(),
g_node_next_sibling() or g_node_last_sibling().
</para>
<para>
To get information about a node or tree use G_NODE_IS_LEAF(),
G_NODE_IS_ROOT(), g_node_depth(), g_node_n_nodes(), g_node_n_children(),
g_node_is_ancestor() or g_node_max_height().
</para>
<para>
To traverse a tree, calling a function for each node visited in the
traversal, use g_node_traverse() or g_node_children_foreach().
</para>
<para>
To remove a node or subtree from a tree use g_node_unlink() or
g_node_destroy().
</para>
<!-- ##### SECTION See_Also ##### -->
<para>
</para>
<!-- ##### SECTION Stability_Level ##### -->
<!-- ##### STRUCT GNode ##### -->
<para>
The <structname>GNode</structname> struct represents one node in a
<link linkend="glib-N-ary-Trees">N-ary Tree</link>.
fields
</para>
@data: contains the actual data of the node.
@next: points to the node's next sibling (a sibling is another
<structname>GNode</structname> with the same parent).
@prev: points to the node's previous sibling.
@parent: points to the parent of the <structname>GNode</structname>,
or is %NULL if the <structname>GNode</structname> is the root of the tree.
@children: The <structfield>children</structfield> field points to the first
child of the <structname>GNode</structname>. The other children are accessed
by using the <structfield>next</structfield> pointer of each child.
<!-- ##### FUNCTION g_node_new ##### -->
<para>
</para>
@data:
@Returns:
<!-- ##### FUNCTION g_node_copy ##### -->
<para>
</para>
@node:
@Returns:
<!-- ##### USER_FUNCTION GCopyFunc ##### -->
<para>
</para>
@src:
@data:
@Returns:
<!-- ##### FUNCTION g_node_copy_deep ##### -->
<para>
</para>
@node:
@copy_func:
@data:
@Returns:
<!-- ##### FUNCTION g_node_insert ##### -->
<para>
</para>
@parent:
@position:
@node:
@Returns:
<!-- ##### FUNCTION g_node_insert_before ##### -->
<para>
</para>
@parent:
@sibling:
@node:
@Returns:
<!-- ##### FUNCTION g_node_insert_after ##### -->
<para>
</para>
@parent:
@sibling:
@node:
@Returns:
<!-- ##### MACRO g_node_append ##### -->
<para>
</para>
@parent:
@node:
@Returns:
<!-- ##### FUNCTION g_node_prepend ##### -->
<para>
</para>
@parent:
@node:
@Returns:
<!-- ##### MACRO g_node_insert_data ##### -->
<para>
</para>
@parent:
@position:
@data:
@Returns:
<!-- ##### MACRO g_node_insert_data_before ##### -->
<para>
</para>
@parent:
@sibling:
@data:
@Returns:
<!-- ##### MACRO g_node_append_data ##### -->
<para>
</para>
@parent:
@data:
@Returns:
<!-- ##### MACRO g_node_prepend_data ##### -->
<para>
</para>
@parent:
@data:
@Returns:
<!-- ##### FUNCTION g_node_reverse_children ##### -->
<para>
</para>
@node:
<!-- ##### FUNCTION g_node_traverse ##### -->
<para>
</para>
@root:
@order:
@flags:
@max_depth:
@func:
@data:
<!-- ##### ENUM GTraverseFlags ##### -->
<para>
Specifies which nodes are visited during several of the tree functions,
including g_node_traverse() and g_node_find().
</para>
@G_TRAVERSE_LEAVES: only leaf nodes should be visited. This name has been
introduced in 2.6, for older version use %G_TRAVERSE_LEAFS.
@G_TRAVERSE_NON_LEAVES: only non-leaf nodes should be visited. This name
has been introduced in 2.6, for older version use %G_TRAVERSE_NON_LEAFS.
@G_TRAVERSE_ALL: all nodes should be visited.
@G_TRAVERSE_MASK: a mask of all traverse flags.
@G_TRAVERSE_LEAFS: identical to %G_TRAVERSE_LEAVES.
@G_TRAVERSE_NON_LEAFS: identical to %G_TRAVERSE_NON_LEAVES.
<!-- ##### USER_FUNCTION GNodeTraverseFunc ##### -->
<para>
Specifies the type of function passed to g_node_traverse().
The function is called with each of the nodes visited, together with the
user data passed to g_node_traverse().
If the function returns %TRUE, then the traversal is stopped.
</para>
@node: a #GNode.
@data: user data passed to g_node_traverse().
@Returns: %TRUE to stop the traversal.
<!-- ##### FUNCTION g_node_children_foreach ##### -->
<para>
</para>
@node:
@flags:
@func:
@data:
<!-- ##### USER_FUNCTION GNodeForeachFunc ##### -->
<para>
Specifies the type of function passed to g_node_children_foreach().
The function is called with each child node, together with the user data
passed to g_node_children_foreach().
</para>
@node: a #GNode.
@data: user data passed to g_node_children_foreach().
<!-- ##### FUNCTION g_node_get_root ##### -->
<para>
</para>
@node:
@Returns:
<!-- ##### FUNCTION g_node_find ##### -->
<para>
</para>
@root:
@order:
@flags:
@data:
@Returns:
<!-- ##### FUNCTION g_node_find_child ##### -->
<para>
</para>
@node:
@flags:
@data:
@Returns:
<!-- ##### FUNCTION g_node_child_index ##### -->
<para>
</para>
@node:
@data:
@Returns:
<!-- ##### FUNCTION g_node_child_position ##### -->
<para>
</para>
@node:
@child:
@Returns:
<!-- ##### MACRO g_node_first_child ##### -->
<para>
</para>
@node:
@Returns:
<!-- ##### FUNCTION g_node_last_child ##### -->
<para>
</para>
@node:
@Returns:
<!-- ##### FUNCTION g_node_nth_child ##### -->
<para>
</para>
@node:
@n:
@Returns:
<!-- ##### FUNCTION g_node_first_sibling ##### -->
<para>
</para>
@node:
@Returns:
<!-- ##### MACRO g_node_next_sibling ##### -->
<para>
</para>
@node:
@Returns:
<!-- ##### MACRO g_node_prev_sibling ##### -->
<para>
</para>
@node:
@Returns:
<!-- ##### FUNCTION g_node_last_sibling ##### -->
<para>
</para>
@node:
@Returns:
<!-- ##### MACRO G_NODE_IS_LEAF ##### -->
<para>
</para>
@node:
@Returns:
<!-- ##### MACRO G_NODE_IS_ROOT ##### -->
<para>
</para>
@node:
@Returns:
<!-- ##### FUNCTION g_node_depth ##### -->
<para>
</para>
@node:
@Returns:
<!-- ##### FUNCTION g_node_n_nodes ##### -->
<para>
</para>
@root:
@flags:
@Returns:
<!-- ##### FUNCTION g_node_n_children ##### -->
<para>
</para>
@node:
@Returns:
<!-- ##### FUNCTION g_node_is_ancestor ##### -->
<para>
</para>
@node:
@descendant:
@Returns:
<!-- ##### FUNCTION g_node_max_height ##### -->
<para>
</para>
@root:
@Returns:
<!-- ##### FUNCTION g_node_unlink ##### -->
<para>
</para>
@node:
<!-- ##### FUNCTION g_node_destroy ##### -->
<para>
</para>
@root:
<!-- ##### FUNCTION g_node_push_allocator ##### -->
<para>
Sets the allocator to use to allocate #GNode elements.
Use g_node_pop_allocator() to restore the previous allocator.
</para>
<para>
Note that this function is not available if GLib has been compiled
with <option>--disable-mem-pools</option>
</para>
@dummy: the #GAllocator to use when allocating #GNode elements.
@Deprecated: 2.10: It does nothing, since #GNode has been converted
to the <link linkend="glib-Memory-Slices">slice allocator</link>
<!-- ##### FUNCTION g_node_pop_allocator ##### -->
<para>
Restores the previous #GAllocator, used when allocating #GNode elements.
</para>
<para>
Note that this function is not available if GLib has been compiled
with <option>--disable-mem-pools</option>
</para>
@Deprecated: 2.10: It does nothing, since #GNode has been converted
to the <link linkend="glib-Memory-Slices">slice allocator</link>