mirror of https://gitee.com/bigwinds/arangodb
fixed memleaks
This commit is contained in:
parent
39cf9c527c
commit
a51c258bf5
|
@ -28,18 +28,18 @@
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include "V8Traverser.h"
|
#include "V8Traverser.h"
|
||||||
#include "v8.h"
|
#include "Utils/transactions.h"
|
||||||
|
#include "Utils/V8ResolverGuard.h"
|
||||||
|
#include "Utils/CollectionNameResolver.h"
|
||||||
#include "V8/v8-conv.h"
|
#include "V8/v8-conv.h"
|
||||||
#include "V8/v8-utils.h"
|
#include "V8/v8-utils.h"
|
||||||
#include "V8Server/v8-vocbaseprivate.h"
|
#include "V8Server/v8-vocbaseprivate.h"
|
||||||
#include "V8Server/v8-wrapshapedjson.h"
|
#include "V8Server/v8-wrapshapedjson.h"
|
||||||
#include "V8Server/v8-vocindex.h"
|
#include "V8Server/v8-vocindex.h"
|
||||||
#include "V8Server/v8-collection.h"
|
#include "V8Server/v8-collection.h"
|
||||||
#include "Utils/transactions.h"
|
|
||||||
#include "Utils/V8ResolverGuard.h"
|
|
||||||
#include "Utils/CollectionNameResolver.h"
|
|
||||||
#include "VocBase/document-collection.h"
|
#include "VocBase/document-collection.h"
|
||||||
#include "VocBase/key-generator.h"
|
#include "VocBase/key-generator.h"
|
||||||
|
#include <v8.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace triagens::basics;
|
using namespace triagens::basics;
|
||||||
|
@ -224,15 +224,16 @@ class SimpleEdgeExpander {
|
||||||
/// @brief Insert a new vertex matcher object
|
/// @brief Insert a new vertex matcher object
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void BasicOptions::addVertexFilter(
|
void BasicOptions::addVertexFilter (v8::Isolate* isolate,
|
||||||
v8::Isolate* isolate,
|
|
||||||
v8::Handle<v8::Value> const& example,
|
v8::Handle<v8::Value> const& example,
|
||||||
ExplicitTransaction* trx,
|
ExplicitTransaction* trx,
|
||||||
TRI_transaction_collection_t* col,
|
TRI_transaction_collection_t* col,
|
||||||
TRI_shaper_t* shaper,
|
TRI_shaper_t* shaper,
|
||||||
TRI_voc_cid_t const& cid,
|
TRI_voc_cid_t const& cid,
|
||||||
string& errorMessage) {
|
string& errorMessage) {
|
||||||
|
|
||||||
auto it = _vertexFilter.find(cid);
|
auto it = _vertexFilter.find(cid);
|
||||||
|
|
||||||
if (example->IsArray()) {
|
if (example->IsArray()) {
|
||||||
if (it == _vertexFilter.end()) {
|
if (it == _vertexFilter.end()) {
|
||||||
_vertexFilter.emplace(cid, VertexFilterInfo(
|
_vertexFilter.emplace(cid, VertexFilterInfo(
|
||||||
|
@ -241,7 +242,8 @@ void BasicOptions::addVertexFilter(
|
||||||
new ExampleMatcher(isolate, v8::Handle<v8::Array>::Cast(example), shaper, errorMessage)
|
new ExampleMatcher(isolate, v8::Handle<v8::Array>::Cast(example), shaper, errorMessage)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
// Has to be Object
|
// Has to be Object
|
||||||
if (it == _vertexFilter.end()) {
|
if (it == _vertexFilter.end()) {
|
||||||
_vertexFilter.emplace(cid, VertexFilterInfo(
|
_vertexFilter.emplace(cid, VertexFilterInfo(
|
||||||
|
@ -257,13 +259,14 @@ void BasicOptions::addVertexFilter(
|
||||||
/// @brief Checks if a vertex matches to given examples
|
/// @brief Checks if a vertex matches to given examples
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
bool BasicOptions::matchesVertex (VertexId& v) const {
|
bool BasicOptions::matchesVertex (VertexId const& v) const {
|
||||||
if (!useVertexFilter) {
|
if (! useVertexFilter) {
|
||||||
// Nothing to do
|
// Nothing to do
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto it = _vertexFilter.find(v.cid);
|
auto it = _vertexFilter.find(v.cid);
|
||||||
|
|
||||||
if (it == _vertexFilter.end()) {
|
if (it == _vertexFilter.end()) {
|
||||||
// This collection does not have any object of this shape.
|
// This collection does not have any object of this shape.
|
||||||
// Short circuit.
|
// Short circuit.
|
||||||
|
@ -271,31 +274,33 @@ bool BasicOptions::matchesVertex (VertexId& v) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
TRI_doc_mptr_copy_t vertex;
|
TRI_doc_mptr_copy_t vertex;
|
||||||
|
|
||||||
int res = it->second.trx->readSingle(it->second.col, &vertex, v.key);
|
int res = it->second.trx->readSingle(it->second.col, &vertex, v.key);
|
||||||
|
|
||||||
if (res != TRI_ERROR_NO_ERROR) {
|
if (res != TRI_ERROR_NO_ERROR) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return it->second.matcher->matches(v.cid, &vertex);
|
return it->second.matcher->matches(v.cid, &vertex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief Insert a new edge matcher object
|
/// @brief Insert a new edge matcher object
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void BasicOptions::addEdgeFilter (
|
void BasicOptions::addEdgeFilter (v8::Isolate* isolate,
|
||||||
v8::Isolate* isolate,
|
|
||||||
v8::Handle<v8::Value> const& example,
|
v8::Handle<v8::Value> const& example,
|
||||||
TRI_shaper_t* shaper,
|
TRI_shaper_t* shaper,
|
||||||
TRI_voc_cid_t const& cid,
|
TRI_voc_cid_t const& cid,
|
||||||
string& errorMessage) {
|
string& errorMessage) {
|
||||||
auto it = _edgeFilter.find(cid);
|
auto it = _edgeFilter.find(cid);
|
||||||
|
|
||||||
if (example->IsArray()) {
|
if (example->IsArray()) {
|
||||||
if (it == _edgeFilter.end()) {
|
if (it == _edgeFilter.end()) {
|
||||||
_edgeFilter.emplace(cid, new ExampleMatcher(isolate, v8::Handle<v8::Array>::Cast(example), shaper, errorMessage));
|
_edgeFilter.emplace(cid, new ExampleMatcher(isolate, v8::Handle<v8::Array>::Cast(example), shaper, errorMessage));
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
// Has to be Object
|
// Has to be Object
|
||||||
if (it == _edgeFilter.end()) {
|
if (it == _edgeFilter.end()) {
|
||||||
_edgeFilter.emplace(cid, new ExampleMatcher(isolate, v8::Handle<v8::Object>::Cast(example), shaper, errorMessage));
|
_edgeFilter.emplace(cid, new ExampleMatcher(isolate, v8::Handle<v8::Object>::Cast(example), shaper, errorMessage));
|
||||||
|
@ -308,16 +313,19 @@ void BasicOptions::addEdgeFilter (
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
bool BasicOptions::matchesEdge (EdgeId& e, TRI_doc_mptr_copy_t* edge) const {
|
bool BasicOptions::matchesEdge (EdgeId& e, TRI_doc_mptr_copy_t* edge) const {
|
||||||
if (!useEdgeFilter) {
|
if (! useEdgeFilter) {
|
||||||
// Nothing to do
|
// Nothing to do
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto it = _edgeFilter.find(e.cid);
|
auto it = _edgeFilter.find(e.cid);
|
||||||
|
|
||||||
if (it == _edgeFilter.end()) {
|
if (it == _edgeFilter.end()) {
|
||||||
// This collection does not have any object of this shape.
|
// This collection does not have any object of this shape.
|
||||||
// Short circuit.
|
// Short circuit.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return it->second->matches(e.cid, edge);
|
return it->second->matches(e.cid, edge);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -329,10 +337,11 @@ bool BasicOptions::matchesEdge (EdgeId& e, TRI_doc_mptr_copy_t* edge) const {
|
||||||
/// @brief Checks if a vertex matches to given examples
|
/// @brief Checks if a vertex matches to given examples
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
bool ShortestPathOptions::matchesVertex (VertexId& v) const {
|
bool ShortestPathOptions::matchesVertex (VertexId const& v) const {
|
||||||
if (start == v || end == v) {
|
if (start == v || end == v) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return BasicOptions::matchesVertex(v);
|
return BasicOptions::matchesVertex(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -344,9 +353,9 @@ bool ShortestPathOptions::matchesVertex (VertexId& v) const {
|
||||||
/// @brief Checks if a vertex matches to given examples
|
/// @brief Checks if a vertex matches to given examples
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
bool NeighborsOptions::matchesVertex (VertexId& v) const {
|
bool NeighborsOptions::matchesVertex (VertexId const& v) const {
|
||||||
// If there are explicitly marked collections check them.
|
// If there are explicitly marked collections check them.
|
||||||
if (_explicitCollections.size() > 0) {
|
if (! _explicitCollections.empty()) {
|
||||||
// If the current collection is not stored the result is invalid
|
// If the current collection is not stored the result is invalid
|
||||||
if (_explicitCollections.find(v.cid) == _explicitCollections.end()) {
|
if (_explicitCollections.find(v.cid) == _explicitCollections.end()) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -361,7 +370,7 @@ bool NeighborsOptions::matchesVertex (VertexId& v) const {
|
||||||
/// collection all are implicitly allowed.
|
/// collection all are implicitly allowed.
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void NeighborsOptions::addCollectionRestriction (TRI_voc_cid_t& cid) {
|
void NeighborsOptions::addCollectionRestriction (TRI_voc_cid_t cid) {
|
||||||
_explicitCollections.insert(cid);
|
_explicitCollections.insert(cid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -379,20 +388,27 @@ unique_ptr<ArangoDBPathFinder::Path> TRI_RunShortestPathSearch (
|
||||||
|
|
||||||
TRI_edge_direction_e forward;
|
TRI_edge_direction_e forward;
|
||||||
TRI_edge_direction_e backward;
|
TRI_edge_direction_e backward;
|
||||||
|
|
||||||
if (opts.direction == "outbound") {
|
if (opts.direction == "outbound") {
|
||||||
forward = TRI_EDGE_OUT;
|
forward = TRI_EDGE_OUT;
|
||||||
backward = TRI_EDGE_IN;
|
backward = TRI_EDGE_IN;
|
||||||
} else if (opts.direction == "inbound") {
|
}
|
||||||
|
else if (opts.direction == "inbound") {
|
||||||
forward = TRI_EDGE_IN;
|
forward = TRI_EDGE_IN;
|
||||||
backward = TRI_EDGE_OUT;
|
backward = TRI_EDGE_OUT;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
forward = TRI_EDGE_ANY;
|
forward = TRI_EDGE_ANY;
|
||||||
backward = TRI_EDGE_ANY;
|
backward = TRI_EDGE_ANY;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto edgeFilterClosure = [&opts](EdgeId& e, TRI_doc_mptr_copy_t* edge) -> bool {return opts.matchesEdge(e, edge);};
|
auto edgeFilterClosure = [&opts](EdgeId& e, TRI_doc_mptr_copy_t* edge) -> bool {
|
||||||
|
return opts.matchesEdge(e, edge);
|
||||||
|
};
|
||||||
|
|
||||||
auto vertexFilterClosure = [&opts](VertexId& v) -> bool { return opts.matchesVertex(v); };
|
auto vertexFilterClosure = [&opts](VertexId& v) -> bool {
|
||||||
|
return opts.matchesVertex(v);
|
||||||
|
};
|
||||||
|
|
||||||
MultiCollectionEdgeExpander forwardExpander(forward, collectionInfos, edgeFilterClosure, vertexFilterClosure);
|
MultiCollectionEdgeExpander forwardExpander(forward, collectionInfos, edgeFilterClosure, vertexFilterClosure);
|
||||||
MultiCollectionEdgeExpander backwardExpander(backward, collectionInfos, edgeFilterClosure, vertexFilterClosure);
|
MultiCollectionEdgeExpander backwardExpander(backward, collectionInfos, edgeFilterClosure, vertexFilterClosure);
|
||||||
|
@ -414,21 +430,23 @@ unique_ptr<ArangoDBPathFinder::Path> TRI_RunShortestPathSearch (
|
||||||
/// @brief search for distinct inbound neighbors
|
/// @brief search for distinct inbound neighbors
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
static void inboundNeighbors (
|
static void InboundNeighbors (vector<EdgeCollectionInfo*>& collectionInfos,
|
||||||
vector<EdgeCollectionInfo*>& collectionInfos,
|
|
||||||
NeighborsOptions& opts,
|
NeighborsOptions& opts,
|
||||||
unordered_set<VertexId>& startVertices,
|
unordered_set<VertexId>& startVertices,
|
||||||
unordered_set<VertexId>& visited,
|
unordered_set<VertexId>& visited,
|
||||||
unordered_set<VertexId>& distinct,
|
unordered_set<VertexId>& distinct,
|
||||||
vector<VertexId>& result,
|
vector<VertexId>& result,
|
||||||
uint64_t depth = 1) {
|
uint64_t depth = 1) {
|
||||||
|
|
||||||
TRI_edge_direction_e dir = TRI_EDGE_IN;
|
TRI_edge_direction_e dir = TRI_EDGE_IN;
|
||||||
unordered_set<VertexId> nextDepth;
|
unordered_set<VertexId> nextDepth;
|
||||||
for (auto col : collectionInfos) {
|
|
||||||
for (VertexId start : startVertices) {
|
for (auto const& col : collectionInfos) {
|
||||||
|
for (VertexId const& start : startVertices) {
|
||||||
auto edges = col->getEdges(dir, start);
|
auto edges = col->getEdges(dir, start);
|
||||||
for (size_t j = 0; j < edges.size(); ++j) {
|
for (size_t j = 0; j < edges.size(); ++j) {
|
||||||
EdgeId edgeId = col->extractEdgeId(edges[j]);
|
EdgeId edgeId = col->extractEdgeId(edges[j]);
|
||||||
|
|
||||||
if (opts.matchesEdge(edgeId, &edges[j])) {
|
if (opts.matchesEdge(edgeId, &edges[j])) {
|
||||||
VertexId v = extractFromId(edges[j]);
|
VertexId v = extractFromId(edges[j]);
|
||||||
if (visited.find(v) != visited.end()) {
|
if (visited.find(v) != visited.end()) {
|
||||||
|
@ -451,8 +469,9 @@ static void inboundNeighbors (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (nextDepth.size() > 0) {
|
|
||||||
inboundNeighbors(collectionInfos, opts, nextDepth, visited, distinct, result, depth + 1);
|
if (! nextDepth.empty()) {
|
||||||
|
InboundNeighbors(collectionInfos, opts, nextDepth, visited, distinct, result, depth + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -460,19 +479,21 @@ static void inboundNeighbors (
|
||||||
/// @brief search for distinct outbound neighbors
|
/// @brief search for distinct outbound neighbors
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
static void outboundNeighbors (
|
static void OutboundNeighbors (vector<EdgeCollectionInfo*>& collectionInfos,
|
||||||
vector<EdgeCollectionInfo*>& collectionInfos,
|
|
||||||
NeighborsOptions& opts,
|
NeighborsOptions& opts,
|
||||||
unordered_set<VertexId>& startVertices,
|
unordered_set<VertexId>& startVertices,
|
||||||
unordered_set<VertexId>& visited,
|
unordered_set<VertexId>& visited,
|
||||||
unordered_set<VertexId>& distinct,
|
unordered_set<VertexId>& distinct,
|
||||||
vector<VertexId>& result,
|
vector<VertexId>& result,
|
||||||
uint64_t depth = 1) {
|
uint64_t depth = 1) {
|
||||||
|
|
||||||
TRI_edge_direction_e dir = TRI_EDGE_OUT;
|
TRI_edge_direction_e dir = TRI_EDGE_OUT;
|
||||||
|
|
||||||
unordered_set<VertexId> nextDepth;
|
unordered_set<VertexId> nextDepth;
|
||||||
for (auto col : collectionInfos) {
|
for (auto const& col : collectionInfos) {
|
||||||
for (VertexId start : startVertices) {
|
for (VertexId const& start : startVertices) {
|
||||||
auto edges = col->getEdges(dir, start);
|
auto edges = col->getEdges(dir, start);
|
||||||
|
|
||||||
for (size_t j = 0; j < edges.size(); ++j) {
|
for (size_t j = 0; j < edges.size(); ++j) {
|
||||||
EdgeId edgeId = col->extractEdgeId(edges[j]);
|
EdgeId edgeId = col->extractEdgeId(edges[j]);
|
||||||
if (opts.matchesEdge(edgeId, &edges[j])) {
|
if (opts.matchesEdge(edgeId, &edges[j])) {
|
||||||
|
@ -497,8 +518,8 @@ static void outboundNeighbors (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (nextDepth.size() > 0) {
|
if (! nextDepth.empty()) {
|
||||||
outboundNeighbors(collectionInfos, opts, nextDepth, visited, distinct, result, depth + 1);
|
OutboundNeighbors(collectionInfos, opts, nextDepth, visited, distinct, result, depth + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -506,8 +527,7 @@ static void outboundNeighbors (
|
||||||
/// @brief search for distinct in- and outbound neighbors
|
/// @brief search for distinct in- and outbound neighbors
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
static void anyNeighbors (
|
static void AnyNeighbors (vector<EdgeCollectionInfo*>& collectionInfos,
|
||||||
vector<EdgeCollectionInfo*>& collectionInfos,
|
|
||||||
NeighborsOptions& opts,
|
NeighborsOptions& opts,
|
||||||
unordered_set<VertexId>& startVertices,
|
unordered_set<VertexId>& startVertices,
|
||||||
unordered_set<VertexId>& visited,
|
unordered_set<VertexId>& visited,
|
||||||
|
@ -516,10 +536,12 @@ static void anyNeighbors (
|
||||||
uint64_t depth = 1) {
|
uint64_t depth = 1) {
|
||||||
TRI_edge_direction_e dir = TRI_EDGE_OUT;
|
TRI_edge_direction_e dir = TRI_EDGE_OUT;
|
||||||
unordered_set<VertexId> nextDepth;
|
unordered_set<VertexId> nextDepth;
|
||||||
for (auto col : collectionInfos) {
|
|
||||||
for (VertexId start : startVertices) {
|
for (auto const& col : collectionInfos) {
|
||||||
|
for (VertexId const& start : startVertices) {
|
||||||
dir = TRI_EDGE_OUT;
|
dir = TRI_EDGE_OUT;
|
||||||
auto edges = col->getEdges(dir, start);
|
auto edges = col->getEdges(dir, start);
|
||||||
|
|
||||||
for (size_t j = 0; j < edges.size(); ++j) {
|
for (size_t j = 0; j < edges.size(); ++j) {
|
||||||
EdgeId edgeId = col->extractEdgeId(edges[j]);
|
EdgeId edgeId = col->extractEdgeId(edges[j]);
|
||||||
if (opts.matchesEdge(edgeId, &edges[j])) {
|
if (opts.matchesEdge(edgeId, &edges[j])) {
|
||||||
|
@ -568,8 +590,8 @@ static void anyNeighbors (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (nextDepth.size() > 0) {
|
if (! nextDepth.empty()) {
|
||||||
anyNeighbors(collectionInfos, opts, nextDepth, visited, distinct, result, depth + 1);
|
AnyNeighbors(collectionInfos, opts, nextDepth, visited, distinct, result, depth + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -589,13 +611,14 @@ void TRI_RunNeighborsSearch (
|
||||||
|
|
||||||
switch (opts.direction) {
|
switch (opts.direction) {
|
||||||
case TRI_EDGE_IN:
|
case TRI_EDGE_IN:
|
||||||
inboundNeighbors(collectionInfos, opts, startVertices, visited, distinct, result);
|
InboundNeighbors(collectionInfos, opts, startVertices, visited, distinct, result);
|
||||||
break;
|
break;
|
||||||
case TRI_EDGE_OUT:
|
case TRI_EDGE_OUT:
|
||||||
outboundNeighbors(collectionInfos, opts, startVertices, visited, distinct, result);
|
OutboundNeighbors(collectionInfos, opts, startVertices, visited, distinct, result);
|
||||||
break;
|
break;
|
||||||
case TRI_EDGE_ANY:
|
case TRI_EDGE_ANY:
|
||||||
anyNeighbors(collectionInfos, opts, startVertices, visited, distinct, result);
|
AnyNeighbors(collectionInfos, opts, startVertices, visited, distinct, result);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,9 @@ struct VertexId {
|
||||||
TRI_voc_cid_t cid;
|
TRI_voc_cid_t cid;
|
||||||
char const* key;
|
char const* key;
|
||||||
|
|
||||||
VertexId () : cid(0), key(nullptr) {
|
VertexId ()
|
||||||
|
: cid(0),
|
||||||
|
key(nullptr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
VertexId (TRI_voc_cid_t cid, char const* key)
|
VertexId (TRI_voc_cid_t cid, char const* key)
|
||||||
|
@ -68,7 +70,7 @@ namespace std {
|
||||||
template<>
|
template<>
|
||||||
struct hash<VertexId> {
|
struct hash<VertexId> {
|
||||||
public:
|
public:
|
||||||
size_t operator()(VertexId const& s) const {
|
size_t operator() (VertexId const& s) const {
|
||||||
size_t h1 = std::hash<TRI_voc_cid_t>()(s.cid);
|
size_t h1 = std::hash<TRI_voc_cid_t>()(s.cid);
|
||||||
size_t h2 = TRI_FnvHashString(s.key);
|
size_t h2 = TRI_FnvHashString(s.key);
|
||||||
return h1 ^ ( h2 << 1 );
|
return h1 ^ ( h2 << 1 );
|
||||||
|
@ -78,7 +80,7 @@ namespace std {
|
||||||
template<>
|
template<>
|
||||||
struct equal_to<VertexId> {
|
struct equal_to<VertexId> {
|
||||||
public:
|
public:
|
||||||
bool operator()(VertexId const& s, VertexId const& t) const {
|
bool operator() (VertexId const& s, VertexId const& t) const {
|
||||||
return s.cid == t.cid && strcmp(s.key, t.key) == 0;
|
return s.cid == t.cid && strcmp(s.key, t.key) == 0;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -86,7 +88,7 @@ namespace std {
|
||||||
template<>
|
template<>
|
||||||
struct less<VertexId> {
|
struct less<VertexId> {
|
||||||
public:
|
public:
|
||||||
bool operator()(const VertexId& lhs, const VertexId& rhs) {
|
bool operator() (const VertexId& lhs, const VertexId& rhs) {
|
||||||
if (lhs.cid != rhs.cid) {
|
if (lhs.cid != rhs.cid) {
|
||||||
return lhs.cid < rhs.cid;
|
return lhs.cid < rhs.cid;
|
||||||
}
|
}
|
||||||
|
@ -109,12 +111,14 @@ struct VertexFilterInfo {
|
||||||
TRI_transaction_collection_t* col;
|
TRI_transaction_collection_t* col;
|
||||||
triagens::arango::ExampleMatcher* matcher;
|
triagens::arango::ExampleMatcher* matcher;
|
||||||
|
|
||||||
VertexFilterInfo (
|
VertexFilterInfo (triagens::arango::ExplicitTransaction* trx,
|
||||||
triagens::arango::ExplicitTransaction* trx,
|
|
||||||
TRI_transaction_collection_t* col,
|
TRI_transaction_collection_t* col,
|
||||||
triagens::arango::ExampleMatcher* matcher
|
triagens::arango::ExampleMatcher* matcher)
|
||||||
) : trx(trx), col(col), matcher(matcher) {
|
: trx(trx),
|
||||||
|
col(col),
|
||||||
|
matcher(matcher) {
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -124,8 +128,6 @@ struct VertexFilterInfo {
|
||||||
typedef triagens::basics::PathFinder<VertexId, EdgeId, double>
|
typedef triagens::basics::PathFinder<VertexId, EdgeId, double>
|
||||||
ArangoDBPathFinder;
|
ArangoDBPathFinder;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace triagens {
|
namespace triagens {
|
||||||
namespace basics {
|
namespace basics {
|
||||||
namespace traverser {
|
namespace traverser {
|
||||||
|
@ -144,33 +146,39 @@ namespace triagens {
|
||||||
useVertexFilter(false) {
|
useVertexFilter(false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
~BasicOptions () {
|
||||||
|
// properly clean up the mess
|
||||||
|
for (auto& it : _edgeFilter) {
|
||||||
|
delete it.second;
|
||||||
|
}
|
||||||
|
for (auto& it: _vertexFilter) {
|
||||||
|
delete it.second.matcher;
|
||||||
|
it.second.matcher = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
VertexId start;
|
VertexId start;
|
||||||
bool useEdgeFilter;
|
bool useEdgeFilter;
|
||||||
bool useVertexFilter;
|
bool useVertexFilter;
|
||||||
|
|
||||||
|
void addEdgeFilter (v8::Isolate* isolate,
|
||||||
void addEdgeFilter (
|
|
||||||
v8::Isolate* isolate,
|
|
||||||
v8::Handle<v8::Value> const& example,
|
v8::Handle<v8::Value> const& example,
|
||||||
TRI_shaper_t* shaper,
|
TRI_shaper_t* shaper,
|
||||||
TRI_voc_cid_t const& cid,
|
TRI_voc_cid_t const& cid,
|
||||||
std::string& errorMessage
|
std::string& errorMessage);
|
||||||
);
|
|
||||||
|
|
||||||
void addVertexFilter (
|
void addVertexFilter (v8::Isolate* isolate,
|
||||||
v8::Isolate* isolate,
|
|
||||||
v8::Handle<v8::Value> const& example,
|
v8::Handle<v8::Value> const& example,
|
||||||
triagens::arango::ExplicitTransaction* trx,
|
triagens::arango::ExplicitTransaction* trx,
|
||||||
TRI_transaction_collection_t* col,
|
TRI_transaction_collection_t* col,
|
||||||
TRI_shaper_t* shaper,
|
TRI_shaper_t* shaper,
|
||||||
TRI_voc_cid_t const& cid,
|
TRI_voc_cid_t const& cid,
|
||||||
std::string& errorMessage
|
std::string& errorMessage);
|
||||||
);
|
|
||||||
|
|
||||||
bool matchesEdge (EdgeId& e, TRI_doc_mptr_copy_t* edge) const;
|
bool matchesEdge (EdgeId& e, TRI_doc_mptr_copy_t* edge) const;
|
||||||
|
|
||||||
bool matchesVertex (VertexId& v) const;
|
bool matchesVertex (VertexId const& v) const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -184,15 +192,15 @@ namespace triagens {
|
||||||
uint64_t minDepth;
|
uint64_t minDepth;
|
||||||
uint64_t maxDepth;
|
uint64_t maxDepth;
|
||||||
|
|
||||||
NeighborsOptions () :
|
NeighborsOptions ()
|
||||||
direction(TRI_EDGE_OUT),
|
: direction(TRI_EDGE_OUT),
|
||||||
minDepth(1),
|
minDepth(1),
|
||||||
maxDepth(1) {
|
maxDepth(1) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool matchesVertex (VertexId& v) const;
|
bool matchesVertex (VertexId const&) const;
|
||||||
|
|
||||||
void addCollectionRestriction (TRI_voc_cid_t& cid);
|
void addCollectionRestriction (TRI_voc_cid_t cid);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -208,8 +216,8 @@ namespace triagens {
|
||||||
bool multiThreaded;
|
bool multiThreaded;
|
||||||
VertexId end;
|
VertexId end;
|
||||||
|
|
||||||
ShortestPathOptions() :
|
ShortestPathOptions ()
|
||||||
direction("outbound"),
|
: direction("outbound"),
|
||||||
useWeight(false),
|
useWeight(false),
|
||||||
weightAttribute(""),
|
weightAttribute(""),
|
||||||
defaultWeight(1),
|
defaultWeight(1),
|
||||||
|
@ -217,8 +225,7 @@ namespace triagens {
|
||||||
multiThreaded(true) {
|
multiThreaded(true) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool matchesVertex (VertexId const&) const;
|
||||||
bool matchesVertex (VertexId& v) const;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -261,34 +268,33 @@ class EdgeCollectionInfo {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
EdgeCollectionInfo(
|
EdgeCollectionInfo (TRI_voc_cid_t& edgeCollectionCid,
|
||||||
TRI_voc_cid_t& edgeCollectionCid,
|
|
||||||
TRI_document_collection_t* edgeCollection,
|
TRI_document_collection_t* edgeCollection,
|
||||||
WeightCalculatorFunction weighter
|
WeightCalculatorFunction weighter)
|
||||||
) : _edgeCollectionCid(edgeCollectionCid),
|
: _edgeCollectionCid(edgeCollectionCid),
|
||||||
_edgeCollection(edgeCollection),
|
_edgeCollection(edgeCollection),
|
||||||
_weighter(weighter) {
|
_weighter(weighter) {
|
||||||
}
|
}
|
||||||
|
|
||||||
EdgeId extractEdgeId(TRI_doc_mptr_copy_t& ptr) {
|
EdgeId extractEdgeId (TRI_doc_mptr_copy_t& ptr) {
|
||||||
return EdgeId(_edgeCollectionCid, TRI_EXTRACT_MARKER_KEY(&ptr));
|
return EdgeId(_edgeCollectionCid, TRI_EXTRACT_MARKER_KEY(&ptr));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<TRI_doc_mptr_copy_t> getEdges (TRI_edge_direction_e& direction,
|
std::vector<TRI_doc_mptr_copy_t> getEdges (TRI_edge_direction_e direction,
|
||||||
VertexId& vertexId) {
|
VertexId const& vertexId) const {
|
||||||
return TRI_LookupEdgesDocumentCollection(_edgeCollection,
|
return TRI_LookupEdgesDocumentCollection(_edgeCollection,
|
||||||
direction, vertexId.cid, const_cast<char*>(vertexId.key));
|
direction, vertexId.cid, const_cast<char*>(vertexId.key));
|
||||||
}
|
}
|
||||||
|
|
||||||
TRI_voc_cid_t getCid() {
|
TRI_voc_cid_t getCid () {
|
||||||
return _edgeCollectionCid;
|
return _edgeCollectionCid;
|
||||||
}
|
}
|
||||||
|
|
||||||
TRI_shaper_t* getShaper() {
|
TRI_shaper_t* getShaper () {
|
||||||
return _edgeCollection->getShaper();
|
return _edgeCollection->getShaper();
|
||||||
}
|
}
|
||||||
|
|
||||||
double weightEdge(TRI_doc_mptr_copy_t& ptr) {
|
double weightEdge (TRI_doc_mptr_copy_t& ptr) {
|
||||||
return _weighter(ptr);
|
return _weighter(ptr);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -299,6 +305,7 @@ class EdgeCollectionInfo {
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
class VertexCollectionInfo {
|
class VertexCollectionInfo {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -315,22 +322,21 @@ class VertexCollectionInfo {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
VertexCollectionInfo(
|
VertexCollectionInfo (TRI_voc_cid_t& vertexCollectionCid,
|
||||||
TRI_voc_cid_t& vertexCollectionCid,
|
TRI_transaction_collection_t* vertexCollection)
|
||||||
TRI_transaction_collection_t* vertexCollection
|
: _vertexCollectionCid(vertexCollectionCid),
|
||||||
) : _vertexCollectionCid(vertexCollectionCid),
|
|
||||||
_vertexCollection(vertexCollection) {
|
_vertexCollection(vertexCollection) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TRI_voc_cid_t getCid() {
|
TRI_voc_cid_t getCid () {
|
||||||
return _vertexCollectionCid;
|
return _vertexCollectionCid;
|
||||||
}
|
}
|
||||||
|
|
||||||
TRI_transaction_collection_t* getCollection() {
|
TRI_transaction_collection_t* getCollection () {
|
||||||
return _vertexCollection;
|
return _vertexCollection;
|
||||||
}
|
}
|
||||||
|
|
||||||
TRI_shaper_t* getShaper() {
|
TRI_shaper_t* getShaper () {
|
||||||
return _vertexCollection->_collection->_collection->getShaper();
|
return _vertexCollection->_collection->_collection->getShaper();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -341,6 +347,7 @@ class VertexCollectionInfo {
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
/// @brief Wrapper for the shortest path computation
|
/// @brief Wrapper for the shortest path computation
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
std::unique_ptr<ArangoDBPathFinder::Path> TRI_RunShortestPathSearch (
|
std::unique_ptr<ArangoDBPathFinder::Path> TRI_RunShortestPathSearch (
|
||||||
std::vector<EdgeCollectionInfo*>& collectionInfos,
|
std::vector<EdgeCollectionInfo*>& collectionInfos,
|
||||||
triagens::basics::traverser::ShortestPathOptions& opts
|
triagens::basics::traverser::ShortestPathOptions& opts
|
||||||
|
@ -350,11 +357,9 @@ std::unique_ptr<ArangoDBPathFinder::Path> TRI_RunShortestPathSearch (
|
||||||
/// @brief Wrapper for the neighbors computation
|
/// @brief Wrapper for the neighbors computation
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void TRI_RunNeighborsSearch (
|
void TRI_RunNeighborsSearch (std::vector<EdgeCollectionInfo*>& collectionInfos,
|
||||||
std::vector<EdgeCollectionInfo*>& collectionInfos,
|
|
||||||
triagens::basics::traverser::NeighborsOptions& opts,
|
triagens::basics::traverser::NeighborsOptions& opts,
|
||||||
std::unordered_set<VertexId>& distinct,
|
std::unordered_set<VertexId>& distinct,
|
||||||
std::vector<VertexId>& result
|
std::vector<VertexId>& result);
|
||||||
);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -169,7 +169,7 @@ ExampleMatcher::ExampleMatcher (v8::Isolate* isolate,
|
||||||
size_t exCount = examples->Length();
|
size_t exCount = examples->Length();
|
||||||
for (size_t j = 0; j < exCount; ++j) {
|
for (size_t j = 0; j < exCount; ++j) {
|
||||||
auto tmp = examples->Get((uint32_t) j);
|
auto tmp = examples->Get((uint32_t) j);
|
||||||
if (!tmp->IsObject() || tmp->IsArray()) {
|
if (! tmp->IsObject() || tmp->IsArray()) {
|
||||||
// Right now silently ignore this example
|
// Right now silently ignore this example
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,17 +47,17 @@ struct TRI_doc_mptr_t;
|
||||||
namespace triagens {
|
namespace triagens {
|
||||||
namespace arango {
|
namespace arango {
|
||||||
|
|
||||||
|
|
||||||
class ExampleMatcher {
|
class ExampleMatcher {
|
||||||
|
|
||||||
struct DocumentId {
|
struct DocumentId {
|
||||||
TRI_voc_cid_t cid;
|
TRI_voc_cid_t cid;
|
||||||
std::string key;
|
std::string key;
|
||||||
|
|
||||||
DocumentId (
|
DocumentId (TRI_voc_cid_t cid,
|
||||||
TRI_voc_cid_t cid,
|
std::string const& key)
|
||||||
std::string key
|
: cid(cid),
|
||||||
) : cid(cid), key(key) {};
|
key(key) {
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
enum internalAttr {
|
enum internalAttr {
|
||||||
|
@ -76,42 +76,34 @@ namespace triagens {
|
||||||
TRI_shaper_t* _shaper;
|
TRI_shaper_t* _shaper;
|
||||||
std::vector<ExampleDefinition> definitions;
|
std::vector<ExampleDefinition> definitions;
|
||||||
|
|
||||||
void fillExampleDefinition (
|
void fillExampleDefinition (v8::Isolate* isolate,
|
||||||
v8::Isolate* isolate,
|
|
||||||
v8::Handle<v8::Object> const& example,
|
v8::Handle<v8::Object> const& example,
|
||||||
v8::Handle<v8::Array> const& names,
|
v8::Handle<v8::Array> const& names,
|
||||||
size_t& n,
|
size_t& n,
|
||||||
std::string& errorMessage,
|
std::string& errorMessage,
|
||||||
ExampleDefinition& def
|
ExampleDefinition& def);
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ExampleMatcher (
|
ExampleMatcher (v8::Isolate* isolate,
|
||||||
v8::Isolate* isolate,
|
|
||||||
v8::Handle<v8::Object> const example,
|
v8::Handle<v8::Object> const example,
|
||||||
TRI_shaper_t* shaper,
|
TRI_shaper_t* shaper,
|
||||||
std::string& errorMessage
|
std::string& errorMessage);
|
||||||
);
|
|
||||||
|
|
||||||
ExampleMatcher (
|
ExampleMatcher (v8::Isolate* isolate,
|
||||||
v8::Isolate* isolate,
|
|
||||||
v8::Handle<v8::Array> const examples,
|
v8::Handle<v8::Array> const examples,
|
||||||
TRI_shaper_t* shaper,
|
TRI_shaper_t* shaper,
|
||||||
std::string& errorMessage
|
std::string& errorMessage);
|
||||||
);
|
|
||||||
|
|
||||||
ExampleMatcher (
|
ExampleMatcher (TRI_json_t* example,
|
||||||
TRI_json_t* example,
|
TRI_shaper_t* shaper);
|
||||||
TRI_shaper_t* shaper
|
|
||||||
);
|
|
||||||
|
|
||||||
~ExampleMatcher () {
|
~ExampleMatcher () {
|
||||||
cleanup();
|
cleanup();
|
||||||
};
|
};
|
||||||
|
|
||||||
bool matches (TRI_voc_cid_t cid, TRI_doc_mptr_t const* mptr) const;
|
bool matches (TRI_voc_cid_t cid,
|
||||||
|
TRI_doc_mptr_t const* mptr) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue