mirror of https://gitee.com/bigwinds/arangodb
added EndNodeFinder
This commit is contained in:
parent
f2cbaa38e0
commit
0f52db88c9
|
@ -32,6 +32,10 @@
|
|||
namespace triagens {
|
||||
namespace aql {
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- class NodeFinder
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- constructors / destructors
|
||||
// -----------------------------------------------------------------------------
|
||||
|
@ -44,9 +48,9 @@ template<>
|
|||
NodeFinder<ExecutionNode::NodeType>::NodeFinder (ExecutionNode::NodeType lookingFor,
|
||||
std::vector<ExecutionNode*>& out,
|
||||
bool enterSubqueries)
|
||||
: _lookingFor(lookingFor),
|
||||
_out(out),
|
||||
_enterSubqueries(enterSubqueries) {
|
||||
: _lookingFor(lookingFor),
|
||||
_out(out),
|
||||
_enterSubqueries(enterSubqueries) {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -96,6 +100,45 @@ bool NodeFinder<std::vector<ExecutionNode::NodeType>>::before (ExecutionNode* en
|
|||
return false;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- class EndNodeFinder
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- constructors / destructors
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief node finder for one node type
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
EndNodeFinder::EndNodeFinder (std::vector<ExecutionNode*>& out,
|
||||
bool enterSubqueries)
|
||||
: _out(out),
|
||||
_found({ false }),
|
||||
_enterSubqueries(enterSubqueries) {
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- public methods
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief before method for one node type
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool EndNodeFinder::before (ExecutionNode* en) {
|
||||
TRI_ASSERT(! _found.empty());
|
||||
if (! _found.back()) {
|
||||
// no node found yet. note that we found one on this level
|
||||
_out.emplace_back(en);
|
||||
_found[_found.size() - 1] = true;
|
||||
}
|
||||
|
||||
// if we don't need to enter subqueries, we can stop after the first node that we found
|
||||
return (! _enterSubqueries);
|
||||
}
|
||||
|
||||
} // namespace triagens::aql
|
||||
} // namespace triagens
|
||||
|
||||
|
|
|
@ -63,6 +63,36 @@ namespace triagens {
|
|||
}
|
||||
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// --SECTION-- class EndNodeFinder
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class EndNodeFinder final : public WalkerWorker<ExecutionNode> {
|
||||
|
||||
std::vector<ExecutionNode*>& _out;
|
||||
|
||||
std::vector<bool> _found;
|
||||
|
||||
bool _enterSubqueries;
|
||||
|
||||
public:
|
||||
|
||||
EndNodeFinder (std::vector<ExecutionNode*>&,
|
||||
bool);
|
||||
|
||||
bool before (ExecutionNode*) override final;
|
||||
|
||||
bool enterSubquery (ExecutionNode*, ExecutionNode*) override final {
|
||||
_found.push_back(false);
|
||||
return _enterSubqueries;
|
||||
}
|
||||
|
||||
void leaveSubquery (ExecutionNode*, ExecutionNode*) override final {
|
||||
_found.pop_back();
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue