mirror of https://gitee.com/bigwinds/arangodb
Finished with Shortest Path Implementation based on new TRX and VPack API
This commit is contained in:
parent
236aa3ab5f
commit
7113e93c67
|
@ -69,7 +69,6 @@ OperationCursor EdgeCollectionInfo::getEdges(TRI_edge_direction_e direction,
|
|||
|
||||
_searchBuilder.clear();
|
||||
EdgeIndex::buildSearchValue(direction, vertexId, _searchBuilder);
|
||||
LOG(INFO) << _searchBuilder.slice().toJson();
|
||||
return _trx->indexScan(_collectionName,
|
||||
arangodb::Transaction::CursorType::INDEX, _indexId,
|
||||
_searchBuilder.slice(), 0, UINT64_MAX, 1000, false);
|
||||
|
@ -146,7 +145,6 @@ class MultiCollectionEdgeExpander {
|
|||
auto cand = candidates.find(t);
|
||||
if (cand == candidates.end()) {
|
||||
// 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(
|
||||
t, s, currentWeight,
|
||||
edge.get(TRI_VOC_ATTRIBUTE_ID).copyString()));
|
||||
|
@ -469,6 +467,7 @@ std::unique_ptr<ArangoDBPathFinder::Path> TRI_RunShortestPathSearch(
|
|||
std::unique_ptr<ArangoDBConstDistancePathFinder::Path>
|
||||
TRI_RunSimpleShortestPathSearch(
|
||||
std::vector<EdgeCollectionInfo*>& collectionInfos,
|
||||
arangodb::Transaction* trx,
|
||||
ShortestPathOptions& opts) {
|
||||
TRI_edge_direction_e forward;
|
||||
TRI_edge_direction_e backward;
|
||||
|
@ -485,7 +484,7 @@ TRI_RunSimpleShortestPathSearch(
|
|||
}
|
||||
|
||||
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) {
|
||||
for (auto const& edgeCollection : collectionInfos) {
|
||||
TRI_ASSERT(edgeCollection != nullptr);
|
||||
|
@ -498,8 +497,7 @@ TRI_RunSimpleShortestPathSearch(
|
|||
VPackSlice edges = edgeCursor.slice();
|
||||
|
||||
for (auto const& edge : VPackArrayIterator(edges)) {
|
||||
#warning fucking custom type
|
||||
std::string edgeId = edge.get(TRI_VOC_ATTRIBUTE_ID).copyString();
|
||||
std::string edgeId = trx->extractIdString(edge);
|
||||
std::string from = edge.get(TRI_VOC_ATTRIBUTE_FROM).copyString();
|
||||
if (from == v) {
|
||||
std::string to = edge.get(TRI_VOC_ATTRIBUTE_TO).copyString();
|
||||
|
@ -517,7 +515,7 @@ TRI_RunSimpleShortestPathSearch(
|
|||
}
|
||||
};
|
||||
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) {
|
||||
for (auto const& edgeCollection : collectionInfos) {
|
||||
TRI_ASSERT(edgeCollection != nullptr);
|
||||
|
@ -530,8 +528,7 @@ TRI_RunSimpleShortestPathSearch(
|
|||
VPackSlice edges = edgeCursor.slice();
|
||||
|
||||
for (auto const& edge : VPackArrayIterator(edges)) {
|
||||
#warning fucking custom type
|
||||
std::string edgeId = edge.get(TRI_VOC_ATTRIBUTE_ID).copyString();
|
||||
std::string edgeId = trx->extractIdString(edge);
|
||||
std::string from = edge.get(TRI_VOC_ATTRIBUTE_FROM).copyString();
|
||||
if (from == v) {
|
||||
std::string to = edge.get(TRI_VOC_ATTRIBUTE_TO).copyString();
|
||||
|
@ -550,7 +547,7 @@ TRI_RunSimpleShortestPathSearch(
|
|||
};
|
||||
|
||||
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));
|
||||
return path;
|
||||
}
|
||||
|
|
|
@ -385,6 +385,7 @@ std::unique_ptr<ArangoDBPathFinder::Path> TRI_RunShortestPathSearch(
|
|||
std::unique_ptr<ArangoDBConstDistancePathFinder::Path>
|
||||
TRI_RunSimpleShortestPathSearch(
|
||||
std::vector<EdgeCollectionInfo*>& collectionInfos,
|
||||
arangodb::Transaction*,
|
||||
arangodb::traverser::ShortestPathOptions& opts);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -1714,15 +1714,14 @@ static v8::Handle<v8::Value> VertexIdToData(
|
|||
TRI_ASSERT(parts.size() == 2); // All internal _id attributes
|
||||
|
||||
VPackBuilder builder;
|
||||
builder.openArray();
|
||||
builder.openObject();
|
||||
builder.add(TRI_SLICE_KEY_EQUAL, VPackValue(parts[1]));
|
||||
builder.close();
|
||||
builder.add(TRI_VOC_ATTRIBUTE_KEY, VPackValue(parts[1]));
|
||||
builder.close();
|
||||
|
||||
OperationResult opRes = trx->document(parts[0], builder.slice(), options);
|
||||
|
||||
if (!opRes.successful()) {
|
||||
if (opRes.failed()) {
|
||||
LOG(INFO) << opRes.code;
|
||||
v8::EscapableHandleScope scope(isolate);
|
||||
return scope.Escape<v8::Value>(v8::Null(isolate));
|
||||
}
|
||||
|
@ -2152,7 +2151,7 @@ static void JS_QueryShortestPath(
|
|||
std::unique_ptr<ArangoDBConstDistancePathFinder::Path> path;
|
||||
|
||||
try {
|
||||
path = TRI_RunSimpleShortestPathSearch(edgeCollectionInfos, opts);
|
||||
path = TRI_RunSimpleShortestPathSearch(edgeCollectionInfos, trx.get(), opts);
|
||||
} catch (Exception& e) {
|
||||
trx->finish(e.code());
|
||||
TRI_V8_THROW_EXCEPTION(e.code());
|
||||
|
|
Loading…
Reference in New Issue