//////////////////////////////////////////////////////////////////////////////// /// DISCLAIMER /// /// Copyright 2014-2016 ArangoDB GmbH, Cologne, Germany /// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany /// /// Licensed under the Apache License, Version 2.0 (the "License"); /// you may not use this file except in compliance with the License. /// You may obtain a copy of the License at /// /// http://www.apache.org/licenses/LICENSE-2.0 /// /// Unless required by applicable law or agreed to in writing, software /// distributed under the License is distributed on an "AS IS" BASIS, /// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. /// See the License for the specific language governing permissions and /// limitations under the License. /// /// Copyright holder is ArangoDB GmbH, Cologne, Germany /// /// @author Michael Hackstein //////////////////////////////////////////////////////////////////////////////// #ifndef ARANGOD_CLUSTER_CLUSTER_TRAVERSER_H #define ARANGOD_CLUSTER_CLUSTER_TRAVERSER_H 1 #include "VocBase/Traverser.h" namespace arangodb { class CollectionNameResolver; class Transaction; namespace traverser { class ClusterTraversalPath; class ClusterTraverser : public Traverser { friend class ClusterTraversalPath; public: ClusterTraverser( std::vector edgeCollections, TraverserOptions& opts, std::string dbname, Transaction* trx, std::unordered_map> const* expressions) : Traverser(opts, expressions), _edgeCols(edgeCollections), _dbname(dbname), _vertexGetter(this), _edgeGetter(this), _trx(trx) {} ~ClusterTraverser() { } void setStartVertex(std::string const&) override; TraversalPath* next() override; private: void fetchVertices(std::unordered_set&, size_t); bool vertexMatchesCondition(arangodb::velocypack::Slice const&, std::vector const&); class VertexGetter { public: explicit VertexGetter(ClusterTraverser* traverser) : _traverser(traverser) {} bool operator()(std::string const&, std::string const&, size_t, std::string&); private: ClusterTraverser* _traverser; }; class EdgeGetter { public: explicit EdgeGetter(ClusterTraverser* traverser) : _traverser(traverser), _continueConst(1) {} void operator()(std::string const&, std::vector&, size_t*&, size_t&, bool&); private: ClusterTraverser* _traverser; size_t _continueConst; }; std::unordered_map>> _edges; std::unordered_map>> _vertices; std::stack> _iteratorCache; std::vector _edgeCols; std::string _dbname; VertexGetter _vertexGetter; EdgeGetter _edgeGetter; arangodb::velocypack::Builder _builder; arangodb::Transaction* _trx; ////////////////////////////////////////////////////////////////////////////// /// @brief internal cursor to enumerate the paths of a graph ////////////////////////////////////////////////////////////////////////////// std::unique_ptr> _enumerator; }; class ClusterTraversalPath : public TraversalPath { public: ClusterTraversalPath( ClusterTraverser const* traverser, const arangodb::basics::EnumeratedPath& path) : _path(path), _traverser(traverser) {} void pathToVelocyPack(Transaction*, arangodb::velocypack::Builder&) override; void lastEdgeToVelocyPack(Transaction*, arangodb::velocypack::Builder&) override; void lastVertexToVelocyPack(Transaction*, arangodb::velocypack::Builder&) override; private: arangodb::basics::EnumeratedPath _path; ClusterTraverser const* _traverser; }; } // traverser } // triagens #endif