deep.processor.bfs
Breadth first search functions.
To improve the performance and usefulness of the variable data gathered we use a Breadth First Search (BFS) approach. This means scanning all local values before proceeding to the next depth on each.
Node
This is a Node that is used within the Breadth First Search of variables.
Source code in deep/processor/bfs/__init__.py
children: List[Node]
property
The node children.
depth
property
The node value.
parent: ParentNode
property
writable
Get the parent node.
value: NodeValue
property
The node value.
__init__(value=None, children=None, parent=None)
Create a new node to process.
:param (NodValue) value: the value to process :param (list) children: the child nodes for this value :param (ParentNode) parent: the parent node for this node
Source code in deep/processor/bfs/__init__.py
__repr__()
__str__()
add_children(children)
Add children to this node.
:param (list) children: the children to add
NodeValue
The variable value the node represents.
Source code in deep/processor/bfs/__init__.py
__init__(name, value, original_name=None)
Create a new node value.
It is possible to rename variables by providing an original name. This is used when dealing with 'private' variables in classes.
e.g. A variable called _NodeValue__name is used by python to represent the private variable __name. This is not known by devs, so we rename the variable to __name, and keep the original name as _NodeValue__name, so we can show this if required.
:param name: the name of the variable at this scope. :param value: the value of the variable :param original_name: the original name
Source code in deep/processor/bfs/__init__.py
__repr__()
ParentNode
Bases: ABC
This represents the parent node - simple used to attach children to the parent if they are processed.
Source code in deep/processor/bfs/__init__.py
add_child(child)
abstractmethod
breadth_first_search(node, consumer)
Search for variables using BFS.
Starting from the provided node, and using the consumer. Search for variables using BFS.
We call consume, which will add all the child nodes to thr passed node. The return will then tell us to process these or not. If we process them then we append the children to the queue.
By using this queue approach we will process all the top level variables, then all of their children, and so on until we are complete.
:param node: the initial node to start the search :param consumer: the consumer to call on each node