Belle II Software development
DynTree< AProperties, ASubPropertiesFactory >::Node Class Reference

Class for a node in the tree. More...

#include <DynTree.h>

Inheritance diagram for DynTree< AProperties, ASubPropertiesFactory >::Node:

Public Types

using Tree = This
 Type of the tree containing this node.
 
using Properties = AProperties
 Type of the Properties.
 
using Children = std::vector< Node >
 Type of the container of the children of the node.
 

Public Member Functions

ChildrengetChildren ()
 Getter for the children.
 
const ChildrengetChildren () const
 Const getter for the children.
 
void createChildren ()
 Creates the children of the node.
 
template<class AWalker >
void walk (AWalker &walker)
 Calls the walker with each node starting with the top node and continues depth first The walker can signal to skip the children if false is returned.
 
template<class AWalker , class APriorityMeasure >
void walk (AWalker &walker, APriorityMeasure &priority)
 Calls the walker with each node starting with the top node and continues depth first The walker can signal to skip the children if false is returned.
 
int getLevel () const
 Get the level of the node.
 
NodegetParent ()
 Getter of the node one up the hierarchy.
 
const NodegetParent () const
 Const getter of the node one up the hierarchy.
 
TreegetTree () const
 Getter for the tree containing this node.
 

Public Attributes

friend Tree
 Allow the tree access to the node constructor to create the top node.
 

Private Member Functions

void unlink ()
 Remove to node from the tree hierachy.
 

Private Attributes

Treem_tree = nullptr
 Reference to the tree that contains this node.
 
Childrenm_children = nullptr
 Children that are created only if needed.
 
int m_level = 0
 Level of the node within the tree.
 
Nodem_parent = nullptr
 Parent in the tree hierachy of this node.
 

Detailed Description

template<class AProperties, class ASubPropertiesFactory>
class Belle2::TrackFindingCDC::DynTree< AProperties, ASubPropertiesFactory >::Node

Class for a node in the tree.

Definition at line 48 of file DynTree.h.

Member Typedef Documentation

◆ Children

using Children = std::vector<Node>

Type of the container of the children of the node.

Definition at line 61 of file DynTree.h.

◆ Properties

using Properties = AProperties

Type of the Properties.

Definition at line 58 of file DynTree.h.

◆ Tree

using Tree = This

Type of the tree containing this node.

Definition at line 52 of file DynTree.h.

Member Function Documentation

◆ createChildren()

void createChildren ( )
inline

Creates the children of the node.

Definition at line 89 of file DynTree.h.

90 {
91 // ensure the level value fits into unsigned char
92 B2ASSERT("DynTree datastructure only supports levels < 255", getLevel() < 255);
93
94 // Call out to the tree, which is providing the memory for the nodes.
95 Node* parentNode = this;
96 m_children = getTree()->createChildren(parentNode);
97
98 for (Node& child : *m_children) {
99 child.m_level = getLevel() + 1;
100 child.m_parent = this;
101 child.m_tree = getTree();
102 }
103 }
Children * m_children
Children that are created only if needed.
Definition: DynTree.h:210
int getLevel() const
Get the level of the node.
Definition: DynTree.h:188
Tree * getTree() const
Getter for the tree containing this node.
Definition: DynTree.h:203
std::vector< Node > * createChildren(Node *parentNode)
Create child nodes for the given parents.
Definition: DynTree.h:284

◆ getChildren() [1/2]

Children * getChildren ( )
inline

Getter for the children.

Get the dynamically created children. Returns nullptr if they have not yet been created

Definition at line 78 of file DynTree.h.

79 { return m_children; }

◆ getChildren() [2/2]

const Children * getChildren ( ) const
inline

Const getter for the children.

Get the dynamically created children. Returns nullptr if they have not yet been created

Definition at line 85 of file DynTree.h.

86 { return m_children; }

◆ getLevel()

int getLevel ( ) const
inline

Get the level of the node.

Definition at line 188 of file DynTree.h.

188{ return m_level; }
int m_level
Level of the node within the tree.
Definition: DynTree.h:213

◆ getParent() [1/2]

Node * getParent ( )
inline

Getter of the node one up the hierarchy.

Usually the highest node of level 0 has no parent. Return nullptr in this case.

Definition at line 194 of file DynTree.h.

194{ return m_parent; }
Node * m_parent
Parent in the tree hierachy of this node.
Definition: DynTree.h:216

◆ getParent() [2/2]

const Node * getParent ( ) const
inline

Const getter of the node one up the hierarchy.

Usually the highest node of level 0 has no parent. Return nullptr in this case.

Definition at line 200 of file DynTree.h.

200{ return m_parent; }

◆ getTree()

Tree * getTree ( ) const
inline

Getter for the tree containing this node.

Definition at line 203 of file DynTree.h.

203{ return m_tree; }
Tree * m_tree
Reference to the tree that contains this node.
Definition: DynTree.h:207

◆ unlink()

void unlink ( )
inlineprivate

Remove to node from the tree hierachy.

Definition at line 107 of file DynTree.h.

108 {
109 m_parent = nullptr;
110 m_level = 0;
111 m_children = nullptr;
112 m_tree = nullptr;
113 }

◆ walk() [1/2]

void walk ( AWalker &  walker)
inline

Calls the walker with each node starting with the top node and continues depth first The walker can signal to skip the children if false is returned.

Definition at line 120 of file DynTree.h.

121 {
122 static_assert(std::is_assignable<std::function<bool(Node*)>, AWalker>(), "");
123
124 bool walkChildren = walker(this);
125 Children* children = getChildren();
126 if (children and walkChildren) {
127 for (Node& childNode : *children) {
128 childNode.walk(walker);
129 }
130 }
131 }
Children * getChildren()
Getter for the children.
Definition: DynTree.h:78
std::vector< Node > Children
Type of the container of the children of the node.
Definition: DynTree.h:61

◆ walk() [2/2]

void walk ( AWalker &  walker,
APriorityMeasure &  priority 
)
inline

Calls the walker with each node starting with the top node and continues depth first The walker can signal to skip the children if false is returned.

Additionally this version allows for a priority measure that determines which child is traversed first.

Definition at line 139 of file DynTree.h.

140 {
141 static_assert(std::is_assignable<std::function<bool(Node*)>, AWalker>(), "");
142 static_assert(std::is_assignable<std::function<float(Node*)>, APriorityMeasure>(), "");
143
144 bool walkChildren = walker(this);
145 Children* children = getChildren();
146 if (children and walkChildren) {
147 std::vector<std::pair<float, Node*> > prioritisedChildNodes;
148 size_t nChildren = children->size();
149
150 prioritisedChildNodes.reserve(nChildren);
151 // Priorities the child nodes with the priority function.
152 for (Node& childNode : *children) {
153 float childPriority = priority(&childNode);
154 if (std::isnan(childPriority)) continue;
155 prioritisedChildNodes.push_back(std::make_pair(childPriority, &childNode));
156 }
157
158 std::make_heap(prioritisedChildNodes.begin(), prioritisedChildNodes.end());
159
160 while (not prioritisedChildNodes.empty()) {
161 std::pop_heap(prioritisedChildNodes.begin(), prioritisedChildNodes.end());
162 Node* priorityChildNode = prioritisedChildNodes.back().second;
163 prioritisedChildNodes.pop_back();
164
165 priorityChildNode->walk(walker, priority);
166
167 // After the walking the children we reevaluate the priority
168 bool reheap = false;
169 erase_remove_if(prioritisedChildNodes,
170 [&reheap, &priority](std::pair<float, Node*>& prioritisedChildNode) {
171 float childPriority = priority(prioritisedChildNode.second);
172 if (std::isnan(childPriority)) return true;
173 // Check if weights changed and a reordering is due.
174 reheap |= prioritisedChildNode.first != childPriority;
175 prioritisedChildNode.first = childPriority;
176 return false;
177 });
178
179 if (reheap) {
180 std::make_heap(prioritisedChildNodes.begin(), prioritisedChildNodes.end());
181 }
182 }
183 assert(prioritisedChildNodes.empty());
184 }
185 }

Member Data Documentation

◆ m_children

Children* m_children = nullptr
private

Children that are created only if needed.

Definition at line 210 of file DynTree.h.

◆ m_level

int m_level = 0
private

Level of the node within the tree.

Definition at line 213 of file DynTree.h.

◆ m_parent

Node* m_parent = nullptr
private

Parent in the tree hierachy of this node.

Definition at line 216 of file DynTree.h.

◆ m_tree

Tree* m_tree = nullptr
private

Reference to the tree that contains this node.

Definition at line 207 of file DynTree.h.

◆ Tree

friend Tree

Allow the tree access to the node constructor to create the top node.

Definition at line 55 of file DynTree.h.


The documentation for this class was generated from the following file: