![]() |
|
A class used for fast traversals of VdfNetworks in the input-to-output direction. More...
#include <sparseOutputTraverser.h>
Public Types | |
| typedef std::function< bool(const VdfOutput &, const VdfMask &, const VdfInput *) > | OutputCallback |
| Callback used when traversing a network. | |
Public Member Functions | |
| VDF_API | VdfSparseOutputTraverser (bool enableCaching=true) |
| Creates a new VdfSparseOutputTraverser. | |
| VDF_API void | InvalidateAll () |
| Invalidates all cached traversals. | |
Static Public Attributes | |
| static const int | MaxRequestsBeforeEviction = 10 |
| The number of requests to remain in the cache. | |
Output Traversal | |
| VDF_API void | TraverseWithCaching (const VdfMaskedOutputVector &outputs, const OutputCallback &outputCallback, const VdfNodeCallback &nodeCallback) |
Traverses the network, starting from the masked outputs in request. | |
| static VDF_API void | Traverse (const VdfMaskedOutputVector &outputs, const OutputCallback &outputCallback, const VdfNodeCallback &nodeCallback) |
Traverses the network, starting from the masked outputs in outputs. | |
A class used for fast traversals of VdfNetworks in the input-to-output direction.
The VdfSparseOutputTraverser class can be used to quickly traverse networks. The main API are the TraverseOnce() and Traverse() methods. The static and non-static methods should have exactly the same behavior. The non-static method has the opportunity to perform much faster traversals if similar traversals are repeatedly invoked using the same traverser object (when caching is enabled).
Definition at line 39 of file sparseOutputTraverser.h.
| typedef std::function< bool (const VdfOutput &, const VdfMask &, const VdfInput *) > OutputCallback |
Callback used when traversing a network.
The callback is supplied with the current output, a mask for the output, and the input through which the current output was reached, if any.
Called for each output traversed. If the callback returns false, traversal will be stopped at that output.
Definition at line 76 of file sparseOutputTraverser.h.
| VDF_API VdfSparseOutputTraverser | ( | bool | enableCaching = true | ) |
Creates a new VdfSparseOutputTraverser.
enableCaching controls whether or not traversals should cache information that can be used to speed up similar traversals later. By default traversal caching is enabled.
| VDF_API void InvalidateAll | ( | ) |
Invalidates all cached traversals.
To be called if network changes.
|
static |
Traverses the network, starting from the masked outputs in outputs.
Performs an optimized vectorized traversal.
Calls outputCallback for each output that is visited, passing the accumulated dependency mask. If the callback returns true, traversal continues; otherwise, it terminates. The outputCallback is optional and may be null.
Calls nodeCallback for each node that is visited. The nodeCallback is optional and may be null.
| VDF_API void TraverseWithCaching | ( | const VdfMaskedOutputVector & | outputs, |
| const OutputCallback & | outputCallback, | ||
| const VdfNodeCallback & | nodeCallback | ||
| ) |
Traverses the network, starting from the masked outputs in request.
In addition to the functionality of the static method Traverse(), this non-static method may be faster because the VdfSparseOutputTraverser object will cache some traversals.
|
static |
The number of requests to remain in the cache.
An attempt to store more than MaxRequestsBeforeEviction requests in the traversal cache will result in the eviction of the m oldest cache entries, such that: cacheSize - m = MaxRequestsBeforeEviction.
This enviction policy is enforced, every time a new traversal is started with TraverseWithCaching.
NOTE: Setting MaxRequestsBeforeEviction to -1 will disable the eviction algorithm all together. 0 will disable caching.
Definition at line 54 of file sparseOutputTraverser.h.