1
0
Fork 0

Edge index lookup returns now TRI_doc_mptr_copy_t.

Move TRI_document_edge_t to voc-types.h.
This commit is contained in:
Max Neunhoeffer 2014-06-10 15:19:11 +02:00
parent ea837012f0
commit 02a8b4e388
5 changed files with 36 additions and 48 deletions

View File

@ -1514,7 +1514,7 @@ static v8::Handle<v8::Value> EdgesQuery (TRI_edge_direction_e direction,
const uint32_t len = vertices->Length();
for (uint32_t i = 0; i < len; ++i) {
TRI_vector_pointer_t edges;
std::vector<TRI_doc_mptr_copy_t> edges;
TRI_voc_cid_t cid;
TRI_voc_key_t key = 0;
@ -1531,8 +1531,8 @@ static v8::Handle<v8::Value> EdgesQuery (TRI_edge_direction_e direction,
TRI_FreeString(TRI_CORE_MEM_ZONE, key);
}
for (size_t j = 0; j < edges._length; ++j) {
v8::Handle<v8::Value> doc = WRAP_SHAPED_JSON(trx, col->_cid, (TRI_doc_mptr_t const*) edges._buffer[j]);
for (size_t j = 0; j < edges.size(); ++j) {
v8::Handle<v8::Value> doc = WRAP_SHAPED_JSON(trx, col->_cid, &edges[j]);
if (doc.IsEmpty()) {
// error
@ -1546,17 +1546,16 @@ static v8::Handle<v8::Value> EdgesQuery (TRI_edge_direction_e direction,
}
TRI_DestroyVectorPointer(&edges);
if (error) {
break;
}
}
trx.finish(res);
}
// argument is a single vertex
else {
TRI_vector_pointer_t edges;
std::vector<TRI_doc_mptr_copy_t> edges;
TRI_voc_key_t key = nullptr;
TRI_voc_cid_t cid;
@ -1569,12 +1568,14 @@ static v8::Handle<v8::Value> EdgesQuery (TRI_edge_direction_e direction,
edges = TRI_LookupEdgesDocumentCollection(document, direction, cid, key);
trx.finish(res);
if (key != nullptr) {
TRI_FreeString(TRI_CORE_MEM_ZONE, key);
}
for (size_t j = 0; j < edges._length; ++j) {
v8::Handle<v8::Value> doc = WRAP_SHAPED_JSON(trx, col->_cid, (TRI_doc_mptr_t const*) edges._buffer[j]);
for (size_t j = 0; j < edges.size(); ++j) {
v8::Handle<v8::Value> doc = WRAP_SHAPED_JSON(trx, col->_cid, &edges[j]);
if (doc.IsEmpty()) {
error = true;
@ -1585,12 +1586,8 @@ static v8::Handle<v8::Value> EdgesQuery (TRI_edge_direction_e direction,
++count;
}
}
TRI_DestroyVectorPointer(&edges);
}
trx.finish(res);
// .............................................................................
// outside a read transaction
// .............................................................................

View File

@ -106,7 +106,7 @@ static bool IsReflexive (TRI_doc_mptr_t const* mptr) {
static bool FindEdges (TRI_edge_direction_e direction,
TRI_edge_index_t* idx,
TRI_vector_pointer_t* result,
std::vector<TRI_doc_mptr_copy_t>& result,
TRI_edge_header_t* entry,
int matchType) {
TRI_vector_pointer_t found;
@ -128,17 +128,10 @@ static bool FindEdges (TRI_edge_direction_e direction,
size_t const n = found._length;
if (n > 0) {
if (result->_capacity == 0) {
if (result.capacity() == 0) {
// if result vector is still empty and we have results, re-init the
// result vector to a "good" size. this will save later reallocations
int res = TRI_InitVectorPointer2(result, TRI_UNKNOWN_MEM_ZONE, n);
if (res != TRI_ERROR_NO_ERROR) {
TRI_DestroyVectorPointer(&found);
TRI_set_errno(res);
return false;
}
result.reserve(n);
}
// add all results found
@ -164,7 +157,7 @@ static bool FindEdges (TRI_edge_direction_e direction,
}
}
TRI_PushBackVectorPointer(result, CONST_CAST(edge));
result.push_back(*edge);
}
}
@ -182,7 +175,7 @@ static bool FindEdges (TRI_edge_direction_e direction,
/// @brief looks up edges
////////////////////////////////////////////////////////////////////////////////
TRI_vector_pointer_t TRI_LookupEdgesDocumentCollection (
std::vector<TRI_doc_mptr_copy_t> TRI_LookupEdgesDocumentCollection (
TRI_document_collection_t* document,
TRI_edge_direction_e direction,
TRI_voc_cid_t cid,
@ -193,8 +186,7 @@ TRI_vector_pointer_t TRI_LookupEdgesDocumentCollection (
entry._key = key;
// initialise the result vector
TRI_vector_pointer_t result;
TRI_InitVectorPointer(&result, TRI_UNKNOWN_MEM_ZONE);
std::vector<TRI_doc_mptr_copy_t> result;
TRI_edge_index_t* edgesIndex = FindEdgesIndex(document);
@ -205,17 +197,17 @@ TRI_vector_pointer_t TRI_LookupEdgesDocumentCollection (
if (direction == TRI_EDGE_IN) {
// get all edges with a matching IN vertex
FindEdges(TRI_EDGE_IN, edgesIndex, &result, &entry, 1);
FindEdges(TRI_EDGE_IN, edgesIndex, result, &entry, 1);
}
else if (direction == TRI_EDGE_OUT) {
// get all edges with a matching OUT vertex
FindEdges(TRI_EDGE_OUT, edgesIndex, &result, &entry, 1);
FindEdges(TRI_EDGE_OUT, edgesIndex, result, &entry, 1);
}
else if (direction == TRI_EDGE_ANY) {
// get all edges with a matching IN vertex
FindEdges(TRI_EDGE_IN, edgesIndex, &result, &entry, 1);
FindEdges(TRI_EDGE_IN, edgesIndex, result, &entry, 1);
// add all non-reflexive edges with a matching OUT vertex
FindEdges(TRI_EDGE_OUT, edgesIndex, &result, &entry, 3);
FindEdges(TRI_EDGE_OUT, edgesIndex, result, &entry, 3);
}
return result;

View File

@ -29,10 +29,8 @@
#define TRIAGENS_VOC_BASE_EDGE_COLLECTION_H 1
#include "Basics/Common.h"
#include "BasicsC/vector.h"
#include "VocBase/voc-types.h"
struct TRI_document_collection_s;
#include "VocBase/document-collection.h"
// -----------------------------------------------------------------------------
// --SECTION-- EDGE COLLECTION
@ -42,19 +40,6 @@ struct TRI_document_collection_s;
// --SECTION-- public types
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @brief edge from and to
////////////////////////////////////////////////////////////////////////////////
typedef struct TRI_document_edge_s {
TRI_voc_cid_t _fromCid;
TRI_voc_key_t _fromKey;
TRI_voc_cid_t _toCid;
TRI_voc_key_t _toKey;
}
TRI_document_edge_t;
////////////////////////////////////////////////////////////////////////////////
/// @brief edge direction
////////////////////////////////////////////////////////////////////////////////
@ -88,7 +73,7 @@ TRI_edge_header_t;
/// @brief looks up edges
////////////////////////////////////////////////////////////////////////////////
TRI_vector_pointer_t TRI_LookupEdgesDocumentCollection (
std::vector<TRI_doc_mptr_copy_t> TRI_LookupEdgesDocumentCollection (
struct TRI_document_collection_s*,
TRI_edge_direction_e,
TRI_voc_cid_t,

View File

@ -142,6 +142,19 @@ typedef enum {
}
TRI_voc_document_operation_e;
////////////////////////////////////////////////////////////////////////////////
/// @brief edge from and to
////////////////////////////////////////////////////////////////////////////////
typedef struct TRI_document_edge_s {
TRI_voc_cid_t _fromCid;
TRI_voc_key_t _fromKey;
TRI_voc_cid_t _toCid;
TRI_voc_key_t _toKey;
}
TRI_document_edge_t;
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////

View File

@ -33,13 +33,14 @@
#include "ShapedJson/Legends.h"
#include "ShapedJson/shaped-json.h"
#include "VocBase/datafile.h"
#include "VocBase/edge-collection.h"
#include "VocBase/voc-types.h"
namespace triagens {
namespace wal {
static_assert(sizeof(TRI_df_marker_t) == 24, "invalid base marker size");
// -----------------------------------------------------------------------------
// --SECTION-- low level structs, used for on-disk persistence
// -----------------------------------------------------------------------------