bpp-phyl3
3.0.0
|
Context for dataflow node construction. More...
#include <Bpp/Phyl/Likelihood/DataFlow/DataFlow.h>
Classes | |
struct | CachedNodeRef |
NodeRef is hashable and comparable as a pointer. CachedNodeRef is hashable and comparable, by comparing the node configuration: More... | |
struct | CachedNodeRefHash |
Public Member Functions | |
Context () | |
NodeRef | cached (NodeRef &&newNode) |
For a newly created node, return its equivalent from the cache. If not already present in the cache, add it and return newNode. If already present in the cache, return the stored one. More... | |
NodeRef | cached (NodeRef &newNode) |
size_t | size () const |
void | clear () |
Clear the context. More... | |
bool | erase (const NodeRef &r) |
Remove an element from the map, only if it has no dependent nodes, and likewise down the graph. More... | |
NodeRef | getZero () |
std::vector< const Node_DF * > | getAllNodes () const |
Returns the vector of all pointers to all nodes. More... | |
Private Attributes | |
std::unordered_set< CachedNodeRef, CachedNodeRefHash > | nodeCache_ |
NodeRef | zero_ |
Context for dataflow node construction.
A context argument is passed to every function constructing dataflow nodes. This class can thus be used to provide construction-time features.
The only feature for now is merging of nodes representing the same value. Each Context instance stores the set of nodes created with it. When passed to a node creation function (create, derive, recreate), the set is updated and used to prevent duplicate nodes. Internally, creation functions will call Context::cached(newlyCreatedNode), which will return an old node and discard the new if it already exists, or update the set and return the new node. Note that the Context owns shared_ptr to nodes, so they will not be destroyed unless the context is destroyed. Multiple context can be used for independent computations.
Nodes are merged if they represent the same value. As the value is not computed yet, two nodes are merged if they have:
Definition at line 526 of file DataFlow.h.
bpp::Context::Context | ( | ) |
Definition at line 311 of file DataFlow.cpp.
For a newly created node, return its equivalent from the cache. If not already present in the cache, add it and return newNode. If already present in the cache, return the stored one.
The returned node is always of the same derived class than newNode. It represents the same value.
Definition at line 315 of file DataFlow.cpp.
References nodeCache_.
Referenced by bpp::cachedAs().
Definition at line 323 of file DataFlow.cpp.
References nodeCache_.
void bpp::Context::clear | ( | ) |
bool bpp::Context::erase | ( | const NodeRef & | r | ) |
Remove an element from the map, only if it has no dependent nodes, and likewise down the graph.
r | the upstream node to be removed |
Definition at line 363 of file DataFlow.cpp.
References nodeCache_.
Referenced by bpp::LikelihoodCalculation::cleanAllLikelihoods(), bpp::AlignedLikelihoodCalculation::cleanAllLikelihoods(), and clear().
std::vector< const Node_DF * > bpp::Context::getAllNodes | ( | ) | const |
Returns the vector of all pointers to all nodes.
Definition at line 352 of file DataFlow.cpp.
References nodeCache_.
|
inline |
Definition at line 568 of file DataFlow.h.
References zero_.
Referenced by bpp::LikelihoodCalculationOnABranch::makeLikelihoods(), and bpp::LikelihoodCalculationSingleProcess::makeLikelihoodsAtRoot_().
|
inline |
Definition at line 543 of file DataFlow.h.
References nodeCache_.
|
private |
Definition at line 605 of file DataFlow.h.
Referenced by cached(), clear(), erase(), getAllNodes(), and size().
|
private |
Definition at line 607 of file DataFlow.h.
Referenced by getZero().