Skip to content

GLib.Node

record (struct)

The Node struct represents one node in a n-ary tree.

Methods

child_index

def child_index(self, data: int | None = ...) -> int

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

Parameters:

  • data — the data to find

child_position

def child_position(self, child: Node) -> int

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 of node

children_foreach

def children_foreach(self, flags: TraverseFlags | int, func: NodeForeachFunc) -> None

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:

depth

def depth(self) -> int

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

def destroy(self) -> None

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

is_ancestor

def is_ancestor(self, descendant: Node) -> bool

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 — a Node

max_height

def max_height(self) -> int

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

def n_children(self) -> int

Gets the number of children of a Node.

n_nodes

def n_nodes(self, flags: TraverseFlags | int) -> int

Gets the number of nodes in a tree.

Parameters:

reverse_children

def reverse_children(self) -> None

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:

def unlink(self) -> None

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

Static functions

pop_allocator

@staticmethod
def pop_allocator() -> None

:::warning Deprecated since 2.10 This API is deprecated. :::

push_allocator

@staticmethod
def push_allocator(allocator: Allocator) -> None

:::warning Deprecated since 2.10 This API is deprecated. :::

Properties

data

data: int  # read/write

next

next: Node  # read/write

prev

prev: Node  # read/write

parent

parent: Node  # read/write

children

children: Node  # read/write