GLib.Node¶
record (struct)
The Node struct represents one node in a n-ary tree.
Methods¶
child_index¶
Gets the position of the first child of a Node
which contains the given data.
Parameters:
data— the data to find
child_position¶
Gets the position of a Node with respect to its siblings.
child must be a child of node. The first child is numbered 0,
the second 1, and so on.
Parameters:
child— a child ofnode
children_foreach¶
Calls a function for each of the children of a Node. Note that it
doesn't descend beneath the child nodes. func must not do anything
that would modify the structure of the tree.
Parameters:
flags— which types of children are to be visited, one ofTraverseFlags.ALL,TraverseFlags.LEAVESandTraverseFlags.NON_LEAVESfunc— the function to call for each visited node
depth¶
Gets the depth of a Node.
If node is None the depth is 0. The root node has a depth of 1.
For the children of the root node the depth is 2. And so on.
destroy¶
Removes root and its children from the tree, freeing any memory
allocated.
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.
Parameters:
descendant— aNode
max_height¶
Gets the maximum height of all branches beneath a Node.
This is the maximum distance from the Node to all leaf nodes.
If root is None, 0 is returned. If root has no children,
1 is returned. If root has children, 2 is returned. And so on.
n_children¶
Gets the number of children of a Node.
n_nodes¶
Gets the number of nodes in a tree.
Parameters:
flags— which types of children are to be counted, one ofTraverseFlags.ALL,TraverseFlags.LEAVESandTraverseFlags.NON_LEAVES
reverse_children¶
Reverses the order of the children of a Node.
(It doesn't change the order of the grandchildren.)
traverse¶
def traverse(self, order: TraverseType | int, flags: TraverseFlags | int, max_depth: int, func: NodeTraverseFunc) -> None
Traverses a tree starting at the given root Node.
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.
Parameters:
order— the order in which nodes are visited -TraverseType.IN_ORDER,TraverseType.PRE_ORDER,TraverseType.POST_ORDER, orTraverseType.LEVEL_ORDER.flags— which types of children are to be visited, one ofTraverseFlags.ALL,TraverseFlags.LEAVESandTraverseFlags.NON_LEAVESmax_depth— the maximum depth of the traversal. Nodes below this depth will not be visited. If max_depth is -1 all nodes in the tree are visited. If depth is 1, only the root is visited. If depth is 2, the root and its children are visited. And so on.func— the function to call for each visitedNode
unlink¶
Unlinks a Node from a tree, resulting in two separate trees.
Static functions¶
pop_allocator¶
:::warning Deprecated since 2.10 This API is deprecated. :::
push_allocator¶
:::warning Deprecated since 2.10 This API is deprecated. :::