mirror of https://gitee.com/bigwinds/arangodb
Sort out mess with strange non-copying.
This commit is contained in:
parent
e30ae28ce5
commit
c55b62b609
|
@ -45,12 +45,14 @@ using namespace std;
|
|||
using namespace triagens::basics;
|
||||
using namespace triagens::arango;
|
||||
|
||||
std::mutex m;
|
||||
|
||||
class SimpleEdgeExpander {
|
||||
|
||||
TRI_edge_direction_e direction;
|
||||
TRI_document_collection_t* edgeCollection;
|
||||
string edgeIdPrefix;
|
||||
CollectionNameResolver const resolver;
|
||||
CollectionNameResolver* resolver;
|
||||
bool usesDist;
|
||||
string id;
|
||||
|
||||
|
@ -60,7 +62,7 @@ class SimpleEdgeExpander {
|
|||
TRI_edge_direction_e direction,
|
||||
TRI_document_collection_t* edgeCollection,
|
||||
string edgeCollectionName,
|
||||
CollectionNameResolver const resolver,
|
||||
CollectionNameResolver* resolver,
|
||||
string id
|
||||
) :
|
||||
direction(direction),
|
||||
|
@ -69,14 +71,14 @@ class SimpleEdgeExpander {
|
|||
usesDist(false),
|
||||
id(id)
|
||||
{
|
||||
cout << id << direction << endl;
|
||||
// cout << id << direction << endl;
|
||||
edgeIdPrefix = edgeCollectionName + "/";
|
||||
};
|
||||
|
||||
Traverser::VertexId extractFromId(TRI_doc_mptr_copy_t& ptr) {
|
||||
char const* key = TRI_EXTRACT_MARKER_FROM_KEY(&ptr);
|
||||
TRI_voc_cid_t cid = TRI_EXTRACT_MARKER_FROM_CID(&ptr);
|
||||
string col = resolver.getCollectionName(cid);
|
||||
string col = resolver->getCollectionName(cid);
|
||||
col.append("/");
|
||||
col.append(key);
|
||||
return col;
|
||||
|
@ -85,7 +87,7 @@ class SimpleEdgeExpander {
|
|||
Traverser::VertexId extractToId(TRI_doc_mptr_copy_t& ptr) {
|
||||
char const* key = TRI_EXTRACT_MARKER_TO_KEY(&ptr);
|
||||
TRI_voc_cid_t cid = TRI_EXTRACT_MARKER_TO_CID(&ptr);
|
||||
string col = resolver.getCollectionName(cid);
|
||||
string col = resolver->getCollectionName(cid);
|
||||
col.append("/");
|
||||
col.append(key);
|
||||
return col;
|
||||
|
@ -99,7 +101,9 @@ class SimpleEdgeExpander {
|
|||
void operator() ( Traverser::VertexId source,
|
||||
vector<Traverser::Neighbor>& result
|
||||
) {
|
||||
cout << "Hallole: " << id << endl;
|
||||
//std::lock_guard<std::mutex> guard(m);
|
||||
|
||||
// cout << "Hallole: " << id << endl;
|
||||
std::vector<TRI_doc_mptr_copy_t> edges;
|
||||
TransactionBase fake(true); // Fake a transaction to please checks. Due to multi-threading
|
||||
// Process Vertex Id!
|
||||
|
@ -115,7 +119,7 @@ class SimpleEdgeExpander {
|
|||
memcpy(buffer, str + split + 1, length);
|
||||
buffer[length] = '\0';
|
||||
|
||||
auto col = resolver.getCollectionStruct(collectionName);
|
||||
auto col = resolver->getCollectionStruct(collectionName);
|
||||
if (col == nullptr) {
|
||||
// collection not found
|
||||
throw TRI_ERROR_ARANGO_COLLECTION_NOT_FOUND;
|
||||
|
@ -124,7 +128,7 @@ class SimpleEdgeExpander {
|
|||
edges = TRI_LookupEdgesDocumentCollection(edgeCollection, direction, collectionCId, buffer);
|
||||
|
||||
if (direction == 1) {
|
||||
cout << edges.size() << endl;
|
||||
// cout << edges.size() << endl;
|
||||
}
|
||||
|
||||
std::unordered_map<Traverser::VertexId, Traverser::Neighbor> candidates;
|
||||
|
@ -324,8 +328,8 @@ void TRI_RunDijkstraSearch (const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||
TRI_document_collection_t* ecol = trx.trxCollection(col->_cid)->_collection->_collection;
|
||||
CollectionNameResolver resolver1(vocbase);
|
||||
CollectionNameResolver resolver2(vocbase);
|
||||
SimpleEdgeExpander forwardExpander(TRI_EDGE_OUT, ecol, edgeCollectionName, resolver1, "A");
|
||||
SimpleEdgeExpander backwardExpander(TRI_EDGE_IN, ecol, edgeCollectionName, resolver2, "B");
|
||||
SimpleEdgeExpander forwardExpander(TRI_EDGE_OUT, ecol, edgeCollectionName, &resolver1, "A");
|
||||
SimpleEdgeExpander backwardExpander(TRI_EDGE_IN, ecol, edgeCollectionName, &resolver2, "B");
|
||||
|
||||
Traverser traverser(forwardExpander, backwardExpander);
|
||||
unique_ptr<Traverser::Path> path(traverser.ShortestPath(startVertex, targetVertex));
|
||||
|
|
|
@ -123,7 +123,7 @@ class Searcher : public Thread {
|
|||
|
||||
virtual void run () {
|
||||
|
||||
cout << _id << ": inserting " << _start << endl;
|
||||
//cout << _id << ": inserting " << _start << endl;
|
||||
string empty;
|
||||
insertNeighbor(_myInfo, _start, empty, empty, 0);
|
||||
auto nextVertexIt = _myInfo.queue.begin();
|
||||
|
@ -133,12 +133,12 @@ class Searcher : public Thread {
|
|||
// there still is a vertex on the stack.
|
||||
while (!_traverser->bingo && nextVertexIt != _myInfo.queue.end()) {
|
||||
auto nextVertex = *nextVertexIt;
|
||||
cout << _id << ": next " << nextVertex.vertex << endl;
|
||||
//cout << _id << ": next " << nextVertex.vertex << endl;
|
||||
_myInfo.queue.erase(nextVertexIt);
|
||||
neighbors.clear();
|
||||
_expander(nextVertex.vertex, neighbors);
|
||||
for (auto& neighbor : neighbors) {
|
||||
cout << _id << ": neighbor " << neighbor.neighbor << endl;
|
||||
//cout << _id << ": neighbor " << neighbor.neighbor << endl;
|
||||
insertNeighbor(_myInfo, neighbor.neighbor, nextVertex.vertex,
|
||||
neighbor.edge, nextVertex.weight + neighbor.weight);
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ class Searcher : public Thread {
|
|||
auto nextVertexLookup = _myInfo.lookup.find(nextVertex.vertex);
|
||||
|
||||
TRI_ASSERT(nextVertexLookup != _myInfo.lookup.end());
|
||||
cout << _id << ": done " << nextVertexLookup->first << endl;
|
||||
//cout << _id << ": done " << nextVertexLookup->first << endl;
|
||||
|
||||
nextVertexLookup->second.done = true;
|
||||
_myInfo.mutex.unlock();
|
||||
|
@ -166,8 +166,8 @@ class Searcher : public Thread {
|
|||
Traverser::Path* Traverser::ShortestPath (VertexId const& start,
|
||||
VertexId const& target) {
|
||||
|
||||
cout << "Forwardexpander: " << &forwardExpander << endl;
|
||||
cout << "Backwardexpander: " << &backwardExpander << endl;
|
||||
//cout << "Forwardexpander: " << &_forwardExpander << endl;
|
||||
//cout << "Backwardexpander: " << &_backwardExpander << endl;
|
||||
std::vector<VertexId> r_vertices;
|
||||
std::vector<VertexId> r_edges;
|
||||
highscore = 1e50;
|
||||
|
@ -183,15 +183,15 @@ Traverser::Path* Traverser::ShortestPath (VertexId const& start,
|
|||
ThreadInfo backwardInfo(_backwardLookup, _backwardQueue, _backwardMutex);
|
||||
|
||||
Searcher forwardSearcher(this, forwardInfo, backwardInfo, start,
|
||||
forwardExpander, "X");
|
||||
_forwardExpander, "X");
|
||||
Searcher backwardSearcher(this, backwardInfo, forwardInfo, target,
|
||||
backwardExpander, "Y");
|
||||
_backwardExpander, "Y");
|
||||
forwardSearcher.start();
|
||||
backwardSearcher.start();
|
||||
forwardSearcher.join();
|
||||
backwardSearcher.join();
|
||||
|
||||
cout << forwardInfo.lookup.size() << backwardInfo.lookup.size() << endl;
|
||||
//cout << forwardInfo.lookup.size() << backwardInfo.lookup.size() << endl;
|
||||
|
||||
if (!bingo || intermediate == "") {
|
||||
return nullptr;
|
||||
|
|
|
@ -505,13 +505,13 @@ namespace triagens {
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Traverser (
|
||||
ExpanderFunction const& forwardExpander,
|
||||
ExpanderFunction const& backwardExpander
|
||||
ExpanderFunction forwardExpander,
|
||||
ExpanderFunction backwardExpander
|
||||
) : highscore(1e50),
|
||||
bingo(false),
|
||||
intermediate(""),
|
||||
forwardExpander(forwardExpander),
|
||||
backwardExpander(backwardExpander) {
|
||||
_forwardExpander(forwardExpander),
|
||||
_backwardExpander(backwardExpander) {
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -609,8 +609,8 @@ namespace triagens {
|
|||
};
|
||||
|
||||
|
||||
ExpanderFunction const& forwardExpander;
|
||||
ExpanderFunction const& backwardExpander;
|
||||
ExpanderFunction _forwardExpander;
|
||||
ExpanderFunction _backwardExpander;
|
||||
|
||||
// ShortestPath will create these variables
|
||||
std::unordered_map<VertexId, LookupInfo> _forwardLookup;
|
||||
|
|
Loading…
Reference in New Issue