Loading...
Searching...
No Matches
gtsam::treeTraversal Namespace Reference

Internal functions used for traversing trees. More...

## Functions

template<class FOREST, typename DATA, typename VISITOR_PRE, typename VISITOR_POST>
void | DepthFirstForest (FOREST &forest, DATA &rootData, VISITOR_PRE &visitorPre, VISITOR_POST &visitorPost)
| Traverse a forest depth-first with pre-order and post-order visits.
template<class FOREST, typename DATA, typename VISITOR_PRE>
void | DepthFirstForest (FOREST &forest, DATA &rootData, VISITOR_PRE &visitorPre)
| Traverse a forest depth-first, with a pre-order visit but no post-order visit.
template<class FOREST, typename DATA, typename VISITOR_PRE, typename VISITOR_POST>
void | DepthFirstForestParallel (FOREST &forest, DATA &rootData, VISITOR_PRE &visitorPre, VISITOR_POST &visitorPost, int problemSizeThreshold=10)
| Traverse a forest depth-first with pre-order and post-order visits.
template<class FOREST>
FastVector< boost::shared_ptr< typename FOREST::Node > > | CloneForest (const FOREST &forest)
| Clone a tree, copy-constructing new nodes (calling boost::make_shared) and setting up child pointers for a clone of the original tree.
template<class FOREST>
void | PrintForest (const FOREST &forest, std::string str, const KeyFormatter &keyFormatter)
| Print a tree, prefixing each line with `str`, and formatting keys using `keyFormatter`.

## Detailed Description

Internal functions used for traversing trees.

Traversal function for PrintForest.

Traversal function for CloneForest.

## Function Documentation

## CloneForest()

template<class FOREST>

FastVector< boost::shared_ptr< typename FOREST::Node > > gtsam::treeTraversal::CloneForest | ( | const FOREST & | forest | ) |

Clone a tree, copy-constructing new nodes (calling boost::make_shared) and setting up child pointers for a clone of the original tree.

Parameters

  forest | The forest of trees to clone. The method `forest.roots()` should exist and return a collection of shared pointers to `FOREST::Node`.

Returns
  The new collection of roots.

## DepthFirstForest() [1/2]

template<class FOREST, typename DATA, typename VISITOR_PRE>

void gtsam::treeTraversal::DepthFirstForest | ( | FOREST & | forest,
|  | DATA & | rootData,
|  | VISITOR_PRE & | visitorPre )

Traverse a forest depth-first, with a pre-order visit but no post-order visit.

Parameters

  forest | The forest of trees to traverse. The method `forest.roots()` should exist and return a collection of (shared) pointers to `FOREST::Node`.

  visitorPre

  `visitorPre(node, parentData)` will be called at every node, before visiting its children, and will be passed, by reference, the `DATA` object returned by the visit to its parent. Likewise, `visitorPre` should return the `DATA` object to pass to the children. The returned `DATA` object will be copy-constructed only upon returning to store internally, thus may be modified by visiting the children. Regarding efficiency, this copy-on-return is usually optimized out by the compiler.

  rootData | The data to pass by reference to `visitorPre` when it is called on each root node.

## DepthFirstForest() [2/2]

template<class FOREST, typename DATA, typename VISITOR_PRE, typename VISITOR_POST>

void gtsam::treeTraversal::DepthFirstForest | ( | FOREST & | forest,
|  | DATA & | rootData,
|  | VISITOR_PRE & | visitorPre,
|  | VISITOR_POST & | visitorPost )

Traverse a forest depth-first with pre-order and post-order visits.

Parameters

  forest | The forest of trees to traverse. The method `forest.roots()` should exist and return a collection of (shared) pointers to `FOREST::Node`.

  visitorPre

  `visitorPre(node, parentData)` will be called at every node, before visiting its children, and will be passed, by reference, the `DATA` object returned by the visit to its parent. Likewise, `visitorPre` should return the `DATA` object to pass to the children. The returned `DATA` object will be copy-constructed only upon returning to store internally, thus may be modified by visiting the children. Regarding efficiency, this copy-on-return is usually optimized out by the compiler.

  visitorPost | `visitorPost(node, data)` will be called at every node, after visiting its children, and will be passed, by reference, the `DATA` object returned by the call to `visitorPre` (the `DATA` object may be modified by visiting the children).
  rootData | The data to pass by reference to `visitorPre` when it is called on each root node.

## DepthFirstForestParallel()

template<class FOREST, typename DATA, typename VISITOR_PRE, typename VISITOR_POST>

void gtsam::treeTraversal::DepthFirstForestParallel | ( | FOREST & | forest,
|  | DATA & | rootData,
|  | VISITOR_PRE & | visitorPre,
|  | VISITOR_POST & | visitorPost,
|  | int | problemSizeThreshold = 10 )

Traverse a forest depth-first with pre-order and post-order visits.

Parameters

  forest | The forest of trees to traverse. The method `forest.roots()` should exist and return a collection of (shared) pointers to `FOREST::Node`.

  visitorPre

  `visitorPre(node, parentData)` will be called at every node, before visiting its children, and will be passed, by reference, the `DATA` object returned by the visit to its parent. Likewise, `visitorPre` should return the `DATA` object to pass to the children. The returned `DATA` object will be copy-constructed only upon returning to store internally, thus may be modified by visiting the children. Regarding efficiency, this copy-on-return is usually optimized out by the compiler.

  visitorPost | `visitorPost(node, data)` will be called at every node, after visiting its children, and will be passed, by reference, the `DATA` object returned by the call to `visitorPre` (the `DATA` object may be modified by visiting the children).
  rootData | The data to pass by reference to `visitorPre` when it is called on each root node.

## PrintForest()

template<class FOREST>

void gtsam::treeTraversal::PrintForest | ( | const FOREST & | forest,
|  | std::string | str,
|  | const KeyFormatter & | keyFormatter )

Print a tree, prefixing each line with `str`, and formatting keys using `keyFormatter`.

To print each node, this function calls the `print` function of the tree nodes.