sailfish.quad_tree.Node

class sailfish.quad_tree.Node(value=None, children=None, items=None)[source]

Bases: object

Represents a node in a self-similar n-tree.

__init__(value=None, children=None, items=None)[source]

Construct a new node.

Zero or one of the keyword arguments value, children, items may be specified. If zero arguments are given then the node has no children and value of None. If value is given, the node has no children and the given value. If children (a sequence containing exactly 4 Node instances) is given, the node has value None and the given child nodes. If items is given (a well-formed sequence of (index, value) pairs like that returned from Node.items), the node is reconstructed from that sequence.

Methods

__init__([value, children, items])

Construct a new node.

at(index)

Return the node at the given index below this one.

from_items(items)

Return a node constructed from a well-formed (index, value) sequence.

indexes([parent])

Return an iterator of index values reflecting this tree's topology.

items()

Return a zipped sequence of indexes and values.

nodes()

Pre-order traversal of the nodes at and below this one.

require(index)

Create if necessary, and return the node at the given index.

values()

Pre-order traversal of the values at and below this node.

Attributes

children

Return the children list, or an empty list if there are no children.

depth

Return the maximum depth of any node below this one.

value

Return the value of this node.

at(index)[source]

Return the node at the given index below this one.

Raises IndexError if the node does not exist.

property children

Return the children list, or an empty list if there are no children.

property depth

Return the maximum depth of any node below this one.

classmethod from_items(items)[source]

Return a node constructed from a well-formed (index, value) sequence.

This makes it possible to reconstruct a node from a sequence of its items, for example:

node == Node.from_items(node.items()) # True

indexes(parent=())[source]

Return an iterator of index values reflecting this tree’s topology.

items()[source]

Return a zipped sequence of indexes and values.

nodes()[source]

Pre-order traversal of the nodes at and below this one.

require(index)[source]

Create if necessary, and return the node at the given index.

This function creates all intermediate nodes that are needed; the created nodes will have value = None.

property value

Return the value of this node.

values()[source]

Pre-order traversal of the values at and below this node.