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

This is the base class for all hough trees. More...

#include <DynTree.h>

Classes

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

Public Member Functions

 DynTree (const Properties &properties, const SubPropertiesFactory &subPropertiesFactory=SubPropertiesFactory())
 Constructor taking properties with which the top node of the tree is initialised.
 
 DynTree (const DynTree &node)=delete
 Forbid copy construction.
 
DynTreeoperator= (const DynTree &)=delete
 Forbid copy assignment.
 
NodegetTopNode ()
 Getter for the top node of the tree.
 
const NodegetTopNode () const
 Constant getter for the top node of the tree.
 
int getNNodes () const
 Gets the number of nodes currently contained in the tree Also demonstrates how to walk over the tree.
 
std::map< int, int > getNNodesByLevel () const
 Gets the number of nodes by level in the tree Also demonstrates how to walk over the tree.
 
template<class AWalker>
void walk (AWalker &walker)
 Forward walk to the top node.
 
template<class AWalker, class APriorityMeasure>
void walk (AWalker &walker, APriorityMeasure &priority)
 Forward walk to the top node.
 
void fell ()
 Fell to tree meaning deleting all child nodes from the tree. Keeps the top node.
 
void raze ()
 Like fell but also releases all memory the tree has acquired during long execution.
 

Public Attributes

SubPropertiesFactory m_subPropertiesFactory
 Instance of the properties factory for the sub nodes.
 
Node m_topNode
 Memory for the top node of the tree.
 
std::deque< typename Node::Childrenm_children
 Central point to provide memory for the child structures.
 
size_t m_nUsedChildren = 0
 Last index of used children.
 

Private Types

using This = DynTree<AProperties, ASubPropertiesFactory>
 Type of this class.
 
using Properties = AProperties
 Type of the Properties.
 
using SubPropertiesFactory = ASubPropertiesFactory
 Type of the factory for the sub node properties.
 

Private Member Functions

std::vector< Node > * createChildren (Node *parentNode)
 Create child nodes for the given parents.
 
std::vector< Node > * getUnusedChildren ()
 Acquire the next unused child node structure, recycling all memory.
 

Detailed Description

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

This is the base class for all hough trees.

It stores its children trees (each tree has children trees itself to reuse this class) as nodes, and has basic functionality to fill and go through ( = walk) all its children and the chdilren of its children etc.

Definition at line 35 of file DynTree.h.

Member Typedef Documentation

◆ Properties

template<class AProperties, class ASubPropertiesFactory>
using Properties = AProperties
private

Type of the Properties.

Definition at line 41 of file DynTree.h.

◆ SubPropertiesFactory

template<class AProperties, class ASubPropertiesFactory>
using SubPropertiesFactory = ASubPropertiesFactory
private

Type of the factory for the sub node properties.

Definition at line 44 of file DynTree.h.

◆ This

template<class AProperties, class ASubPropertiesFactory>
using This = DynTree<AProperties, ASubPropertiesFactory>
private

Type of this class.

Definition at line 38 of file DynTree.h.

Constructor & Destructor Documentation

◆ DynTree()

template<class AProperties, class ASubPropertiesFactory>
DynTree ( const Properties & properties,
const SubPropertiesFactory & subPropertiesFactory = SubPropertiesFactory() )
inlineexplicit

Constructor taking properties with which the top node of the tree is initialised.

Definition at line 221 of file DynTree.h.

222 :
223 m_subPropertiesFactory(subPropertiesFactory),
224 m_topNode(properties),
225 m_children()
226 {
227 m_topNode.m_tree = this;
228 }

Member Function Documentation

◆ createChildren()

template<class AProperties, class ASubPropertiesFactory>
std::vector< Node > * createChildren ( Node * parentNode)
inlineprivate

Create child nodes for the given parents.

Definition at line 284 of file DynTree.h.

285 {
286 std::vector<Node>* result = getUnusedChildren();
287 auto subProperties = m_subPropertiesFactory(*parentNode);
288 if (subProperties.empty()) {
289 result->clear();
290 } else {
291 // Initialize new elements with dummy property.
292 result->resize(subProperties.size(), Node(subProperties.back()));
293 size_t iSubNode = 0;
294 for (auto& properties : subProperties) {
295 clearIfApplicable(result->at(iSubNode));
296 result->at(iSubNode) = properties;
297 ++iSubNode;
298 }
299 }
300 return result;
301 }

◆ fell()

template<class AProperties, class ASubPropertiesFactory>
void fell ( )
inline

Fell to tree meaning deleting all child nodes from the tree. Keeps the top node.

Definition at line 334 of file DynTree.h.

335 {
336 clearIfApplicable(m_topNode);
337 m_topNode.unlink();
338 m_topNode.m_tree = this;
339 for (typename Node::Children& children : m_children) {
340 for (Node& node : children) {
341 clearIfApplicable(node);
342 node.unlink();
343 }
344 }
345 m_nUsedChildren = 0;
346 }

◆ getNNodes()

template<class AProperties, class ASubPropertiesFactory>
int getNNodes ( ) const
inline

Gets the number of nodes currently contained in the tree Also demonstrates how to walk over the tree.

Definition at line 248 of file DynTree.h.

249 {
250 int nNodes = 0;
251 auto countNodes = [&nNodes](const Node*) -> bool {
252 ++nNodes;
253 return true;
254 };
255 const_cast<DynTree&>(*this).walk(countNodes);
256 //walk(countNodes);
257 return nNodes;
258 }

◆ getNNodesByLevel()

template<class AProperties, class ASubPropertiesFactory>
std::map< int, int > getNNodesByLevel ( ) const
inline

Gets the number of nodes by level in the tree Also demonstrates how to walk over the tree.

Definition at line 264 of file DynTree.h.

265 {
266 std::map<int, int> nNodesByLevel;
267 auto countNodes = [&nNodesByLevel](const Node * node) -> bool {
268 if (nNodesByLevel.count(node->getLevel()) == 0)
269 {
270 nNodesByLevel[node->getLevel()] = 1;
271 } else
272 {
273 nNodesByLevel[node->getLevel()]++;
274 }
275 return true;
276 };
277 const_cast<DynTree&>(*this).walk(countNodes);
278 //walk(countNodes);
279 return nNodesByLevel;
280 }

◆ getTopNode() [1/2]

template<class AProperties, class ASubPropertiesFactory>
Node & getTopNode ( )
inline

Getter for the top node of the tree.

Definition at line 237 of file DynTree.h.

238 { return m_topNode; }

◆ getTopNode() [2/2]

template<class AProperties, class ASubPropertiesFactory>
const Node & getTopNode ( ) const
inline

Constant getter for the top node of the tree.

Definition at line 241 of file DynTree.h.

242 { return m_topNode; }

◆ getUnusedChildren()

template<class AProperties, class ASubPropertiesFactory>
std::vector< Node > * getUnusedChildren ( )
inlineprivate

Acquire the next unused child node structure, recycling all memory.

Definition at line 304 of file DynTree.h.

305 {
306 if (m_nUsedChildren >= m_children.size()) {
307 m_children.emplace_back();
308 }
309 ++m_nUsedChildren;
310 return &(m_children[m_nUsedChildren - 1]);
311 }

◆ raze()

template<class AProperties, class ASubPropertiesFactory>
void raze ( )
inline

Like fell but also releases all memory the tree has acquired during long execution.

Definition at line 349 of file DynTree.h.

350 {
351 this->fell();
352 m_children.clear();
353 m_children.shrink_to_fit();
354 }

◆ walk() [1/2]

template<class AProperties, class ASubPropertiesFactory>
template<class AWalker>
void walk ( AWalker & walker)
inline

Forward walk to the top node.

Definition at line 316 of file DynTree.h.

317 {
318 static_assert(std::is_assignable<std::function<bool(Node*)>, AWalker>(), "");
319
320 getTopNode().walk(walker);
321 }

◆ walk() [2/2]

template<class AProperties, class ASubPropertiesFactory>
template<class AWalker, class APriorityMeasure>
void walk ( AWalker & walker,
APriorityMeasure & priority )
inline

Forward walk to the top node.

Definition at line 325 of file DynTree.h.

326 {
327 static_assert(std::is_assignable<std::function<bool(Node*)>, AWalker>(), "");
328 static_assert(std::is_assignable<std::function<float(Node*)>, APriorityMeasure>(), "");
329
330 getTopNode().walk(walker, priority);
331 }

Member Data Documentation

◆ m_children

template<class AProperties, class ASubPropertiesFactory>
std::deque<typename Node::Children> m_children

Central point to provide memory for the child structures.

Definition at line 364 of file DynTree.h.

◆ m_nUsedChildren

template<class AProperties, class ASubPropertiesFactory>
size_t m_nUsedChildren = 0

Last index of used children.

Definition at line 367 of file DynTree.h.

◆ m_subPropertiesFactory

template<class AProperties, class ASubPropertiesFactory>
SubPropertiesFactory m_subPropertiesFactory

Instance of the properties factory for the sub nodes.

Definition at line 358 of file DynTree.h.

◆ m_topNode

template<class AProperties, class ASubPropertiesFactory>
Node m_topNode

Memory for the top node of the tree.

Definition at line 361 of file DynTree.h.


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