GLib.Node¶
Fields¶
Name |
Type |
Access |
Description |
---|---|---|---|
children |
r/w |
points to the first child of the |
|
data |
r/w |
contains the actual data of the node. |
|
next |
r/w |
points to the node’s next sibling (a sibling is another |
|
parent |
r/w |
points to the parent of the |
|
prev |
r/w |
points to the node’s previous sibling. |
Methods¶
class |
|
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Details¶
- class GLib.Node¶
The
GLib.Node
struct represents one node in a n-ary tree.- classmethod push_allocator(allocator)[source]¶
- Parameters:
allocator (
GLib.Allocator
) –
- child_index(data)[source]¶
- Parameters:
- Returns:
the index of the child of self which contains data, or -1 if the data is not found
- Return type:
Gets the position of the first child of a
GLib.Node
which contains the given data.
- child_position(child)[source]¶
- Parameters:
child (
GLib.Node
) – a child of self- Returns:
the position of child with respect to its siblings
- Return type:
Gets the position of a
GLib.Node
with respect to its siblings. child must be a child of self. The first child is numbered 0, the second 1, and so on.
- children_foreach(flags, func, *data)[source]¶
- Parameters:
flags (
GLib.TraverseFlags
) – which types of children are to be visited, one ofGLib.TraverseFlags.ALL
,GLib.TraverseFlags.LEAVES
andGLib.TraverseFlags.NON_LEAVES
func (
GLib.NodeForeachFunc
) – the function to call for each visited node
Calls a function for each of the children of a
GLib.Node
. Note that it doesn’t descend beneath the child nodes. func must not do anything that would modify the structure of the tree.
- depth()[source]¶
-
Gets the depth of a
GLib.Node
.If self 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.
- is_ancestor(descendant)[source]¶
- Parameters:
- Returns:
True
if self is an ancestor of descendant- Return type:
Returns
True
if self is an ancestor of descendant. This is true if node is the parent of descendant, or if node is the grandparent of descendant etc.
- max_height()[source]¶
- Returns:
the maximum height of the tree beneath self
- Return type:
Gets the maximum height of all branches beneath a
GLib.Node
. This is the maximum distance from theGLib.Node
to all leaf nodes.If self is
None
, 0 is returned. If self has no children, 1 is returned. If self has children, 2 is returned. And so on.
- n_children()[source]¶
- Returns:
the number of children of self
- Return type:
Gets the number of children of a
GLib.Node
.
- n_nodes(flags)[source]¶
- Parameters:
flags (
GLib.TraverseFlags
) – which types of children are to be counted, one ofGLib.TraverseFlags.ALL
,GLib.TraverseFlags.LEAVES
andGLib.TraverseFlags.NON_LEAVES
- Returns:
the number of nodes in the tree
- Return type:
Gets the number of nodes in a tree.
- reverse_children()[source]¶
Reverses the order of the children of a
GLib.Node
. (It doesn’t change the order of the grandchildren.)
- traverse(order, flags, max_depth, func, *data)[source]¶
- Parameters:
order (
GLib.TraverseType
) – the order in which nodes are visited -GLib.TraverseType.IN_ORDER
,GLib.TraverseType.PRE_ORDER
,GLib.TraverseType.POST_ORDER
, orGLib.TraverseType.LEVEL_ORDER
.flags (
GLib.TraverseFlags
) – which types of children are to be visited, one ofGLib.TraverseFlags.ALL
,GLib.TraverseFlags.LEAVES
andGLib.TraverseFlags.NON_LEAVES
max_depth (
int
) – 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 (
GLib.NodeTraverseFunc
) – the function to call for each visitedGLib.Node
Traverses a tree starting at the given root
GLib.Node
. It calls the given function for each node visited. The traversal can be halted at any point by returningTrue
from func. func must not do anything that would modify the structure of the tree.