//////////////////////////////////////////////////////////////////////////////// /// 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 ARANGODB_GRAPH_BREADTHFIRSTENUMERATOR_H #define ARANGODB_GRAPH_BREADTHFIRSTENUMERATOR_H 1 #include "Basics/Common.h" #include "VocBase/PathEnumerator.h" namespace arangodb { namespace traverser { class Traverser; struct TraverserOptions; } namespace graph { class BreadthFirstEnumerator final : public arangodb::traverser::PathEnumerator { private: ////////////////////////////////////////////////////////////////////////////// /// @brief One entry in the schreier vector ////////////////////////////////////////////////////////////////////////////// struct PathStep { size_t sourceIdx; std::unique_ptr edge; arangodb::StringRef const vertex; public: explicit PathStep(arangodb::StringRef const vertex); PathStep(size_t sourceIdx, std::unique_ptr&& edge, arangodb::StringRef const vertex); ~PathStep(); PathStep(PathStep& other); }; ////////////////////////////////////////////////////////////////////////////// /// @brief Struct to hold all information required to get the list of /// connected edges ////////////////////////////////////////////////////////////////////////////// struct NextStep { size_t sourceIdx; private: NextStep() = delete; public: explicit NextStep(size_t sourceIdx) : sourceIdx(sourceIdx) {} }; ////////////////////////////////////////////////////////////////////////////// /// @brief schreier vector to store the visited vertices ////////////////////////////////////////////////////////////////////////////// std::vector> _schreier; ////////////////////////////////////////////////////////////////////////////// /// @brief Next free index in schreier vector. ////////////////////////////////////////////////////////////////////////////// size_t _schreierIndex; ////////////////////////////////////////////////////////////////////////////// /// @brief Position of the last returned value in the schreier vector ////////////////////////////////////////////////////////////////////////////// size_t _lastReturned; ////////////////////////////////////////////////////////////////////////////// /// @brief Vector to store where to continue search on next depth ////////////////////////////////////////////////////////////////////////////// std::vector _nextDepth; ////////////////////////////////////////////////////////////////////////////// /// @brief Vector storing the position at current search depth ////////////////////////////////////////////////////////////////////////////// std::vector _toSearch; ////////////////////////////////////////////////////////////////////////////// /// @brief Vector storing the position at current search depth ////////////////////////////////////////////////////////////////////////////// std::unordered_set _tmpEdges; ////////////////////////////////////////////////////////////////////////////// /// @brief Marker for the search depth. Used to abort searching. ////////////////////////////////////////////////////////////////////////////// uint64_t _currentDepth; ////////////////////////////////////////////////////////////////////////////// /// @brief position in _toSearch. If this is >= _toSearch.size() we are done /// with this depth. ////////////////////////////////////////////////////////////////////////////// size_t _toSearchPos; public: BreadthFirstEnumerator(arangodb::traverser::Traverser* traverser, arangodb::velocypack::Slice startVertex, arangodb::traverser::TraverserOptions* opts); ~BreadthFirstEnumerator(); ////////////////////////////////////////////////////////////////////////////// /// @brief Get the next Path element from the traversal. ////////////////////////////////////////////////////////////////////////////// bool next() override; aql::AqlValue lastVertexToAqlValue() override; aql::AqlValue lastEdgeToAqlValue() override; aql::AqlValue pathToAqlValue(arangodb::velocypack::Builder& result) override; private: inline size_t getDepth(size_t index) const { size_t depth = 0; while (index != 0) { ++depth; index = _schreier[index]->sourceIdx; } return depth; } ////////////////////////////////////////////////////////////////////////////// /// @brief Build the enumerated path for the given index in the schreier /// vector. ////////////////////////////////////////////////////////////////////////////// void computeEnumeratedPath(size_t index); }; } } #endif