Struct

GLibNode

Description

struct GNode {
  gpointer data;
  GNode* next;
  GNode* prev;
  GNode* parent;
  GNode* children;
}

The GNode struct represents one node in a [n-ary tree][glib-N-ary-Trees].

Structure members
data

Contains the actual data of the node.

next

Points to the node’s next sibling (a sibling is another GNode with the same parent).

prev

Points to the node’s previous sibling.

parent

Points to the parent of the GNode, or is NULL if the GNode is the root of the tree.

children

Points to the first child of the GNode. The other children are accessed by using the next pointer of each child.

Functions

g_node_new

Creates a new GNode containing the given data. Used to create the first node in a tree.

g_node_pop_allocator
No description available.

g_node_push_allocator
No description available.

Instance methods

g_node_child_index

Gets the position of the first child of a GNode which contains the given data.

g_node_child_position

Gets the position of a GNode with respect to its siblings. child must be a child of node. The first child is numbered 0, the second 1, and so on.

g_node_children_foreach

Calls a function for each of the children of a GNode. Note that it doesn’t descend beneath the child nodes. func must not do anything that would modify the structure of the tree.

g_node_copy

Recursively copies a GNode (but does not deep-copy the data inside the nodes, see g_node_copy_deep() if you need that).

g_node_copy_deep

Recursively copies a GNode and its data.

since: 2.4

g_node_depth

Gets the depth of a GNode.

g_node_destroy

Removes root and its children from the tree, freeing any memory allocated.

g_node_find

Finds a GNode in a tree.

g_node_find_child

Finds the first child of a GNode with the given data.

g_node_first_sibling

Gets the first sibling of a GNode. This could possibly be the node itself.

g_node_get_root

Gets the root of a tree.

g_node_insert

Inserts a GNode beneath the parent at the given position.

g_node_insert_after

Inserts a GNode beneath the parent after the given sibling.

g_node_insert_before

Inserts a GNode beneath the parent before the given sibling.

g_node_is_ancestor

Returns TRUE if node is an ancestor of descendant. This is true if node is the parent of descendant, or if node is the grandparent of descendant etc.

g_node_last_child

Gets the last child of a GNode.

g_node_last_sibling

Gets the last sibling of a GNode. This could possibly be the node itself.

g_node_max_height

Gets the maximum height of all branches beneath a GNode. This is the maximum distance from the GNode to all leaf nodes.

g_node_n_children

Gets the number of children of a GNode.

g_node_n_nodes

Gets the number of nodes in a tree.

g_node_nth_child

Gets a child of a GNode, using the given index. The first child is at index 0. If the index is too big, NULL is returned.

g_node_prepend

Inserts a GNode as the first child of the given parent.

g_node_reverse_children

Reverses the order of the children of a GNode. (It doesn’t change the order of the grandchildren.)

g_node_traverse

Traverses a tree starting at the given root GNode. It calls the given function for each node visited. The traversal can be halted at any point by returning TRUE from func. func must not do anything that would modify the structure of the tree.

g_node_unlink

Unlinks a GNode from a tree, resulting in two separate trees.