1
0
Fork 0

Updated ShortestPathBlock to use the new callback based IndexApi

This commit is contained in:
Michael Hackstein 2017-02-02 15:51:54 +01:00
parent da32eef2ca
commit 08ff23492f
2 changed files with 29 additions and 43 deletions

View File

@ -117,3 +117,4 @@ OpenIssues Hacki
* HashIndex Lookup into a still local buffer, could be replaced by callback as well. * HashIndex Lookup into a still local buffer, could be replaced by callback as well.
* SingleServerTraverser API does NOT takeover responsibility for slice data. getMore() hapes slices to not go away * SingleServerTraverser API does NOT takeover responsibility for slice data. getMore() hapes slices to not go away
* This API can be improved if we make better use of those callbacks. * This API can be improved if we make better use of those callbacks.
* ShortestPathBlock does assume that slices do not walk away.

View File

@ -68,9 +68,6 @@ struct ConstDistanceExpanderLocal {
/// @brief Defines if this expander follows the edges in reverse /// @brief Defines if this expander follows the edges in reverse
bool _isReverse; bool _isReverse;
/// @brief Local cursor vector
std::vector<DocumentIdentifierToken> _cursor;
public: public:
ConstDistanceExpanderLocal(ShortestPathBlock const* block, ConstDistanceExpanderLocal(ShortestPathBlock const* block,
bool isReverse) bool isReverse)
@ -88,31 +85,25 @@ struct ConstDistanceExpanderLocal {
edgeCursor = edgeCollection->getEdges(v, mmdr); edgeCursor = edgeCollection->getEdges(v, mmdr);
} }
// Clear the local cursor before using the
// next edge cursor.
// While iterating over the edge cursor, _cursor
// has to stay intact.
_cursor.clear();
LogicalCollection* collection = edgeCursor->collection(); LogicalCollection* collection = edgeCursor->collection();
while (edgeCursor->hasMore()) { auto cb = [&] (DocumentIdentifierToken const& element) {
edgeCursor->getMoreTokens(_cursor, 1000); if (collection->readDocument(_block->transaction(), *mmdr, element)) {
for (auto const& element : _cursor) { VPackSlice edge(mmdr->vpack());
if (collection->readDocument(_block->transaction(), *mmdr, element)) { VPackSlice from =
VPackSlice edge(mmdr->vpack()); arangodb::Transaction::extractFromFromDocument(edge);
VPackSlice from = if (from == v) {
arangodb::Transaction::extractFromFromDocument(edge); VPackSlice to = arangodb::Transaction::extractToFromDocument(edge);
if (from == v) { if (to != v) {
VPackSlice to = arangodb::Transaction::extractToFromDocument(edge);
if (to != v) {
resEdges.emplace_back(edge);
neighbors.emplace_back(to);
}
} else {
resEdges.emplace_back(edge); resEdges.emplace_back(edge);
neighbors.emplace_back(from); neighbors.emplace_back(to);
} }
} else {
resEdges.emplace_back(edge);
neighbors.emplace_back(from);
} }
} }
};
while (edgeCursor->getMore(cb, 1000)) {
} }
} }
} }
@ -218,7 +209,6 @@ struct EdgeWeightExpanderLocal {
void operator()(VPackSlice const& source, void operator()(VPackSlice const& source,
std::vector<ArangoDBPathFinder::Step*>& result) { std::vector<ArangoDBPathFinder::Step*>& result) {
ManagedDocumentResult* mmdr = _block->_mmdr.get(); ManagedDocumentResult* mmdr = _block->_mmdr.get();
std::vector<DocumentIdentifierToken> cursor;
std::unique_ptr<arangodb::OperationCursor> edgeCursor; std::unique_ptr<arangodb::OperationCursor> edgeCursor;
std::unordered_map<VPackSlice, size_t> candidates; std::unordered_map<VPackSlice, size_t> candidates;
for (auto const& edgeCollection : _block->_collectionInfos) { for (auto const& edgeCollection : _block->_collectionInfos) {
@ -231,28 +221,23 @@ struct EdgeWeightExpanderLocal {
candidates.clear(); candidates.clear();
// Clear the local cursor before using the
// next edge cursor.
// While iterating over the edge cursor, _cursor
// has to stay intact.
cursor.clear();
LogicalCollection* collection = edgeCursor->collection(); LogicalCollection* collection = edgeCursor->collection();
while (edgeCursor->hasMore()) { auto cb = [&] (DocumentIdentifierToken const& element) {
edgeCursor->getMoreTokens(cursor, 1000); if (collection->readDocument(_block->transaction(), *mmdr, element)) {
for (auto const& element : cursor) { VPackSlice edge(mmdr->vpack());
if (collection->readDocument(_block->transaction(), *mmdr, element)) { VPackSlice from =
VPackSlice edge(mmdr->vpack()); arangodb::Transaction::extractFromFromDocument(edge);
VPackSlice from = VPackSlice to = arangodb::Transaction::extractToFromDocument(edge);
arangodb::Transaction::extractFromFromDocument(edge); double currentWeight = edgeCollection->weightEdge(edge);
VPackSlice to = arangodb::Transaction::extractToFromDocument(edge); if (from == source) {
double currentWeight = edgeCollection->weightEdge(edge); inserter(candidates, result, from, to, currentWeight, edge);
if (from == source) { } else {
inserter(candidates, result, from, to, currentWeight, edge); inserter(candidates, result, to, from, currentWeight, edge);
} else {
inserter(candidates, result, to, from, currentWeight, edge);
}
} }
} }
};
while (edgeCursor->getMore(cb, 1000)) {
} }
} }
} }