1
0
Fork 0

Finished with Shortest Path Implementation based on new TRX and VPack API

This commit is contained in:
Michael Hackstein 2016-03-15 20:48:02 +01:00
parent 236aa3ab5f
commit 7113e93c67
3 changed files with 11 additions and 14 deletions

View File

@ -69,7 +69,6 @@ OperationCursor EdgeCollectionInfo::getEdges(TRI_edge_direction_e direction,
_searchBuilder.clear(); _searchBuilder.clear();
EdgeIndex::buildSearchValue(direction, vertexId, _searchBuilder); EdgeIndex::buildSearchValue(direction, vertexId, _searchBuilder);
LOG(INFO) << _searchBuilder.slice().toJson();
return _trx->indexScan(_collectionName, return _trx->indexScan(_collectionName,
arangodb::Transaction::CursorType::INDEX, _indexId, arangodb::Transaction::CursorType::INDEX, _indexId,
_searchBuilder.slice(), 0, UINT64_MAX, 1000, false); _searchBuilder.slice(), 0, UINT64_MAX, 1000, false);
@ -146,7 +145,6 @@ class MultiCollectionEdgeExpander {
auto cand = candidates.find(t); auto cand = candidates.find(t);
if (cand == candidates.end()) { if (cand == candidates.end()) {
// Add weight // Add weight
#warning The third parameter has to be replaced by _id content. We need to extract the internal attribute here. Waiting for JAN
result.emplace_back(new ArangoDBPathFinder::Step( result.emplace_back(new ArangoDBPathFinder::Step(
t, s, currentWeight, t, s, currentWeight,
edge.get(TRI_VOC_ATTRIBUTE_ID).copyString())); edge.get(TRI_VOC_ATTRIBUTE_ID).copyString()));
@ -469,6 +467,7 @@ std::unique_ptr<ArangoDBPathFinder::Path> TRI_RunShortestPathSearch(
std::unique_ptr<ArangoDBConstDistancePathFinder::Path> std::unique_ptr<ArangoDBConstDistancePathFinder::Path>
TRI_RunSimpleShortestPathSearch( TRI_RunSimpleShortestPathSearch(
std::vector<EdgeCollectionInfo*>& collectionInfos, std::vector<EdgeCollectionInfo*>& collectionInfos,
arangodb::Transaction* trx,
ShortestPathOptions& opts) { ShortestPathOptions& opts) {
TRI_edge_direction_e forward; TRI_edge_direction_e forward;
TRI_edge_direction_e backward; TRI_edge_direction_e backward;
@ -485,7 +484,7 @@ TRI_RunSimpleShortestPathSearch(
} }
auto fwExpander = auto fwExpander =
[&collectionInfos, forward](std::string const& v, std::vector<std::string>& res_edges, [&collectionInfos, forward, trx](std::string const& v, std::vector<std::string>& res_edges,
std::vector<std::string>& neighbors) { std::vector<std::string>& neighbors) {
for (auto const& edgeCollection : collectionInfos) { for (auto const& edgeCollection : collectionInfos) {
TRI_ASSERT(edgeCollection != nullptr); TRI_ASSERT(edgeCollection != nullptr);
@ -498,8 +497,7 @@ TRI_RunSimpleShortestPathSearch(
VPackSlice edges = edgeCursor.slice(); VPackSlice edges = edgeCursor.slice();
for (auto const& edge : VPackArrayIterator(edges)) { for (auto const& edge : VPackArrayIterator(edges)) {
#warning fucking custom type std::string edgeId = trx->extractIdString(edge);
std::string edgeId = edge.get(TRI_VOC_ATTRIBUTE_ID).copyString();
std::string from = edge.get(TRI_VOC_ATTRIBUTE_FROM).copyString(); std::string from = edge.get(TRI_VOC_ATTRIBUTE_FROM).copyString();
if (from == v) { if (from == v) {
std::string to = edge.get(TRI_VOC_ATTRIBUTE_TO).copyString(); std::string to = edge.get(TRI_VOC_ATTRIBUTE_TO).copyString();
@ -517,7 +515,7 @@ TRI_RunSimpleShortestPathSearch(
} }
}; };
auto bwExpander = auto bwExpander =
[&collectionInfos, backward](std::string const& v, std::vector<std::string>& res_edges, [&collectionInfos, backward, trx](std::string const& v, std::vector<std::string>& res_edges,
std::vector<std::string>& neighbors) { std::vector<std::string>& neighbors) {
for (auto const& edgeCollection : collectionInfos) { for (auto const& edgeCollection : collectionInfos) {
TRI_ASSERT(edgeCollection != nullptr); TRI_ASSERT(edgeCollection != nullptr);
@ -530,8 +528,7 @@ TRI_RunSimpleShortestPathSearch(
VPackSlice edges = edgeCursor.slice(); VPackSlice edges = edgeCursor.slice();
for (auto const& edge : VPackArrayIterator(edges)) { for (auto const& edge : VPackArrayIterator(edges)) {
#warning fucking custom type std::string edgeId = trx->extractIdString(edge);
std::string edgeId = edge.get(TRI_VOC_ATTRIBUTE_ID).copyString();
std::string from = edge.get(TRI_VOC_ATTRIBUTE_FROM).copyString(); std::string from = edge.get(TRI_VOC_ATTRIBUTE_FROM).copyString();
if (from == v) { if (from == v) {
std::string to = edge.get(TRI_VOC_ATTRIBUTE_TO).copyString(); std::string to = edge.get(TRI_VOC_ATTRIBUTE_TO).copyString();
@ -550,7 +547,7 @@ TRI_RunSimpleShortestPathSearch(
}; };
ArangoDBConstDistancePathFinder pathFinder(fwExpander, bwExpander); ArangoDBConstDistancePathFinder pathFinder(fwExpander, bwExpander);
std::unique_ptr<ArangoDBConstDistancePathFinder::Path> path; auto path = std::make_unique<ArangoDBConstDistancePathFinder::Path>();
path.reset(pathFinder.search(opts.start, opts.end)); path.reset(pathFinder.search(opts.start, opts.end));
return path; return path;
} }

View File

@ -385,6 +385,7 @@ std::unique_ptr<ArangoDBPathFinder::Path> TRI_RunShortestPathSearch(
std::unique_ptr<ArangoDBConstDistancePathFinder::Path> std::unique_ptr<ArangoDBConstDistancePathFinder::Path>
TRI_RunSimpleShortestPathSearch( TRI_RunSimpleShortestPathSearch(
std::vector<EdgeCollectionInfo*>& collectionInfos, std::vector<EdgeCollectionInfo*>& collectionInfos,
arangodb::Transaction*,
arangodb::traverser::ShortestPathOptions& opts); arangodb::traverser::ShortestPathOptions& opts);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View File

@ -1714,15 +1714,14 @@ static v8::Handle<v8::Value> VertexIdToData(
TRI_ASSERT(parts.size() == 2); // All internal _id attributes TRI_ASSERT(parts.size() == 2); // All internal _id attributes
VPackBuilder builder; VPackBuilder builder;
builder.openArray();
builder.openObject(); builder.openObject();
builder.add(TRI_SLICE_KEY_EQUAL, VPackValue(parts[1])); builder.add(TRI_VOC_ATTRIBUTE_KEY, VPackValue(parts[1]));
builder.close();
builder.close(); builder.close();
OperationResult opRes = trx->document(parts[0], builder.slice(), options); OperationResult opRes = trx->document(parts[0], builder.slice(), options);
if (!opRes.successful()) { if (opRes.failed()) {
LOG(INFO) << opRes.code;
v8::EscapableHandleScope scope(isolate); v8::EscapableHandleScope scope(isolate);
return scope.Escape<v8::Value>(v8::Null(isolate)); return scope.Escape<v8::Value>(v8::Null(isolate));
} }
@ -2152,7 +2151,7 @@ static void JS_QueryShortestPath(
std::unique_ptr<ArangoDBConstDistancePathFinder::Path> path; std::unique_ptr<ArangoDBConstDistancePathFinder::Path> path;
try { try {
path = TRI_RunSimpleShortestPathSearch(edgeCollectionInfos, opts); path = TRI_RunSimpleShortestPathSearch(edgeCollectionInfos, trx.get(), opts);
} catch (Exception& e) { } catch (Exception& e) {
trx->finish(e.code()); trx->finish(e.code());
TRI_V8_THROW_EXCEPTION(e.code()); TRI_V8_THROW_EXCEPTION(e.code());