1
0
Fork 0

Change edge index. Compiles but does not work yet.

This commit is contained in:
Max Neunhoeffer 2014-03-28 11:10:49 +01:00
parent 05c9e4fd54
commit 078687fe00
6 changed files with 234 additions and 278 deletions

View File

@ -42,16 +42,12 @@
// --SECTION-- private functions
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup VocBase
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief find the edges index of a document collection
////////////////////////////////////////////////////////////////////////////////
static TRI_multi_pointer_t* FindEdgesIndex (TRI_document_collection_t* const document) {
static TRI_edge_index_t* FindEdgesIndex (
TRI_document_collection_t* const document) {
size_t i, n;
if (document->base.base._info._type != TRI_COL_TYPE_EDGE) {
@ -61,11 +57,11 @@ static TRI_multi_pointer_t* FindEdgesIndex (TRI_document_collection_t* const doc
n = document->_allIndexes._length;
for (i = 0; i < n; ++i) {
TRI_index_t* idx = (TRI_index_t*) TRI_AtVectorPointer(&document->_allIndexes, i);
TRI_index_t* idx
= (TRI_index_t*) TRI_AtVectorPointer(&document->_allIndexes, i);
if (idx->_type == TRI_IDX_TYPE_EDGE_INDEX) {
TRI_edge_index_t* edgesIndex = (TRI_edge_index_t*) idx;
return &edgesIndex->_edges;
return edgesIndex;
}
}
@ -73,14 +69,6 @@ static TRI_multi_pointer_t* FindEdgesIndex (TRI_document_collection_t* const doc
return NULL;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief return whether an edge is self-reflexive
////////////////////////////////////////////////////////////////////////////////
static bool IsReflexive (const TRI_edge_header_t* const edge) {
return ((edge->_flags & TRI_EDGE_BIT_REFLEXIVE) > 0);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief find edges matching search criteria and add them to the result
/// this function is called two times for each edge query:
@ -90,17 +78,28 @@ static bool IsReflexive (const TRI_edge_header_t* const edge) {
////////////////////////////////////////////////////////////////////////////////
static bool FindEdges (const TRI_edge_direction_e direction,
TRI_multi_pointer_t* idx,
TRI_edge_index_t* idx,
TRI_vector_pointer_t* result,
TRI_edge_header_t* entry,
const int matchType) {
TRI_vector_pointer_t found;
TRI_doc_mptr_t* edge;
entry->_flags = TRI_LookupFlagsEdge(direction);
found = TRI_LookupByKeyMultiPointer(TRI_UNKNOWN_MEM_ZONE, idx, entry);
if (direction == TRI_EDGE_OUT) {
found = TRI_LookupByKeyMultiPointer(TRI_UNKNOWN_MEM_ZONE,
&idx->_edges_from,
&entry);
}
else if (direction == TRI_EDGE_IN) {
found = TRI_LookupByKeyMultiPointer(TRI_UNKNOWN_MEM_ZONE,
&idx->_edges_to,
&entry);
}
else {
assert(false); // TRI_EDGE_ANY not supported here
}
if (found._length > 0) {
TRI_edge_header_t* edge;
size_t i;
if (result->_capacity == 0) {
@ -119,99 +118,55 @@ static bool FindEdges (const TRI_edge_direction_e direction,
// add all results found
for (i = 0; i < found._length; ++i) {
edge = (TRI_edge_header_t*) found._buffer[i];
edge = (TRI_doc_mptr_t*) found._buffer[i];
// the following queries will use the following sequences of matchTypes:
// inEdges(): 1, 2, outEdges(): 1, 2, edges(): 1, 3
// inEdges(): 1, outEdges(): 1, edges(): 1, 3
// if matchType is 1, we'll return all found edges without further filtering
//
// if matchType is 2 (inEdges or outEdges query), the direction is reversed.
// We'll exclude all self-reflexive edges now (we already got them in iteration 1),
// if matchType is 1, we'll return all found edges without filtering
// We'll exclude all loop edges now (we already got them in iteration 1),
// and alsoexclude all unidirectional edges
//
// if matchType is 3, the direction is also reversed. We'll exclude all
// self-reflexive edges now (we already got them in iteration 1)
// loop edges now (we already got them in iteration 1)
if (matchType > 1) {
// if the edge is self-reflexive, we have already found it in iteration 1
// if the edge is a loop, we have already found it in iteration 1
// we must skip it here, otherwise we would produce duplicates
if (IsReflexive(edge)) {
continue;
}
//if (IsReflexive(edge)) {
// continue;
//}
}
TRI_PushBackVectorPointer(result, CONST_CAST(edge->_mptr));
TRI_PushBackVectorPointer(result, CONST_CAST(edge));
}
}
TRI_DestroyVectorPointer(&found);
return true;
}
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- public functions
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup VocBase
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief compose edge flags aggregate out of only the direction
////////////////////////////////////////////////////////////////////////////////
TRI_edge_flags_t TRI_LookupFlagsEdge (const TRI_edge_direction_e direction) {
if (direction == TRI_EDGE_IN) {
return TRI_EDGE_BIT_DIRECTION_IN;
}
if (direction == TRI_EDGE_OUT) {
return TRI_EDGE_BIT_DIRECTION_OUT;
}
// invalid direction type
assert(false);
return 0;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief compose edge flags aggregate out of multiple individual parameters
////////////////////////////////////////////////////////////////////////////////
TRI_edge_flags_t TRI_FlagsEdge (const TRI_edge_direction_e direction,
const bool isReflexive) {
TRI_edge_flags_t result = TRI_LookupFlagsEdge(direction);
if (isReflexive) {
result |= TRI_EDGE_BIT_REFLEXIVE;
}
return result;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief looks up edges
////////////////////////////////////////////////////////////////////////////////
TRI_vector_pointer_t TRI_LookupEdgesDocumentCollection (TRI_document_collection_t* document,
TRI_edge_direction_e direction,
TRI_voc_cid_t cid,
TRI_voc_key_t key) {
TRI_vector_pointer_t TRI_LookupEdgesDocumentCollection (
TRI_document_collection_t* document,
TRI_edge_direction_e direction,
TRI_voc_cid_t cid,
TRI_voc_key_t key) {
TRI_vector_pointer_t result;
TRI_edge_header_t entry;
TRI_multi_pointer_t* edgesIndex;
TRI_edge_index_t* edgesIndex;
// search criteria
entry._mptr = NULL;
entry._cid = cid;
entry._searchKey._key = key;
entry._key = key;
// initialise the result vector
TRI_InitVectorPointer(&result, TRI_UNKNOWN_MEM_ZONE);
@ -240,10 +195,6 @@ TRI_vector_pointer_t TRI_LookupEdgesDocumentCollection (TRI_document_collection_
return result;
}
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// Local Variables:
// mode: outline-minor
// outline-regexp: "/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|/// @page\\|// --SECTION--\\|/// @\\}"

View File

@ -126,10 +126,8 @@ TRI_edge_direction_e;
////////////////////////////////////////////////////////////////////////////////
typedef struct TRI_edge_header_s {
TRI_doc_mptr_t const* _mptr;
TRI_voc_cid_t _cid; // from or to, depending on the direction
union { TRI_voc_key_t _key; TRI_voc_size_t _offsetKey; } _searchKey;
TRI_edge_flags_t _flags;
TRI_voc_key_t _key;
}
TRI_edge_header_t;
@ -145,36 +143,15 @@ TRI_edge_header_t;
// --SECTION-- public functions
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup VocBase
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief compose edge flags aggregate out of only the direction
////////////////////////////////////////////////////////////////////////////////
TRI_edge_flags_t TRI_LookupFlagsEdge (const TRI_edge_direction_e);
////////////////////////////////////////////////////////////////////////////////
/// @brief compose edge flags aggregate out of multiple individual parameters
////////////////////////////////////////////////////////////////////////////////
TRI_edge_flags_t TRI_FlagsEdge (const TRI_edge_direction_e,
const bool);
////////////////////////////////////////////////////////////////////////////////
/// @brief looks up edges
////////////////////////////////////////////////////////////////////////////////
TRI_vector_pointer_t TRI_LookupEdgesDocumentCollection (TRI_document_collection_t*,
TRI_edge_direction_e,
TRI_voc_cid_t,
TRI_voc_key_t);
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
TRI_vector_pointer_t TRI_LookupEdgesDocumentCollection (
TRI_document_collection_t*,
TRI_edge_direction_e,
TRI_voc_cid_t,
TRI_voc_key_t);
#ifdef __cplusplus
}

View File

@ -699,111 +699,178 @@ static uint64_t HashElementKey (TRI_multi_pointer_t* array, void const* data) {
char* key;
h = data;
assert(h->_mptr == NULL);
key = h->_searchKey._key;
key = h->_key;
// only include directional bits for hashing, exclude special bits
hash = (uint64_t) (h->_flags & TRI_EDGE_BITS_DIRECTION) ^ h->_cid;
hash = h->_cid;
hash ^= (uint64_t) fasthash64(key, strlen(key), 0x87654321);
return fasthash64(&hash, sizeof(hash), 0x56781234);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief hashes an edge header
/// @brief hashes an edge (_from case)
////////////////////////////////////////////////////////////////////////////////
static uint64_t HashElementEdge (TRI_multi_pointer_t* array, void const* data,
bool byKey) {
TRI_edge_header_t const* h;
static uint64_t HashElementEdgeFrom (TRI_multi_pointer_t* array,
void const* data,
bool byKey) {
TRI_doc_mptr_t const* mptr;
TRI_doc_edge_key_marker_t const* edge;
char const* key;
uint64_t hash;
char const* p;
h = data;
assert(h->_mptr != NULL);
// only include directional bits for hashing, exclude special bits
hash = (uint64_t) (h->_flags & TRI_EDGE_BITS_DIRECTION) ^ h->_cid;
if (byKey) {
p = (char*) h->_mptr->_data + h->_searchKey._offsetKey;
hash ^= (uint64_t) fasthash64(p, strlen(p), 0x87654321);
if (!byKey) {
hash = (uint64_t) data;
}
else {
hash ^= (uint64_t) h->_mptr;
mptr = data;
edge = mptr->_data;
key = (char*) edge + edge->_offsetFromKey;
hash = edge->_fromCid;
hash ^= (uint64_t) fasthash64(key, strlen(key), 0x87654321);
}
return fasthash64(&hash, sizeof(hash), 0x56781234);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief checks if key and element match
/// @brief hashes an edge (_to case)
////////////////////////////////////////////////////////////////////////////////
static bool IsEqualKeyEdge (TRI_multi_pointer_t* array,
void const* left,
void const* right) {
// left is a key, that is with NULL master pointer
// right is an element, that is, with non-NULL master pointer
TRI_edge_header_t const* l;
TRI_edge_header_t const* r;
const char* lKey;
const char* rKey;
static uint64_t HashElementEdgeTo (TRI_multi_pointer_t* array,
void const* data,
bool byKey) {
TRI_doc_mptr_t const* mptr;
TRI_doc_edge_key_marker_t const* edge;
char const* key;
l = left;
r = right;
uint64_t hash;
assert(l->_mptr == NULL);
lKey = l->_searchKey._key;
if (!byKey) {
hash = (uint64_t) data;
}
else {
mptr = data;
edge = mptr->_data;
key = (char*) edge + edge->_offsetToKey;
assert(r->_mptr != NULL);
rKey = ((char*) ((TRI_doc_edge_key_marker_t const*) r->_mptr->_data)) +
r->_searchKey._offsetKey;
hash = edge->_toCid;
hash ^= (uint64_t) fasthash64(key, strlen(key), 0x87654321);
}
// only include directional flags, exclude special bits
return (strcmp(lKey, rKey) == 0) &&
((l->_flags & TRI_EDGE_BITS_DIRECTION) ==
(r->_flags & TRI_EDGE_BITS_DIRECTION)) &&
(l->_cid == r->_cid);
return fasthash64(&hash, sizeof(hash), 0x56781234);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief checks for elements are equal
/// @brief checks if key and element match (_from case)
////////////////////////////////////////////////////////////////////////////////
static bool IsEqualElementEdge (TRI_multi_pointer_t* array,
static bool IsEqualKeyEdgeFrom (TRI_multi_pointer_t* array,
void const* left,
void const* right,
bool byKey) {
void const* right) {
// left is a key
// right is an element, that is a master pointer
TRI_edge_header_t const* l;
TRI_edge_header_t const* r;
TRI_doc_mptr_t const* rMptr;
TRI_doc_edge_key_marker_t const* rEdge;
const char* lKey;
const char* rKey;
l = left;
r = right;
lKey = l->_key;
assert(l->_mptr != NULL);
assert(l->_mptr != NULL);
rMptr = right;
rEdge = rMptr->_data;
rKey = (char*) rEdge + rEdge->_offsetFromKey;
if (byKey) {
lKey = ((char*) ((TRI_doc_edge_key_marker_t const*) l->_mptr->_data)) +
l->_searchKey._offsetKey;
rKey = ((char*) ((TRI_doc_edge_key_marker_t const*) r->_mptr->_data)) +
r->_searchKey._offsetKey;
return (strcmp(lKey, rKey) == 0) &&
((l->_flags & TRI_EDGE_BITS_DIRECTION) ==
(r->_flags & TRI_EDGE_BITS_DIRECTION)) &&
(l->_cid == r->_cid);
return (strcmp(lKey, rKey) == 0) && l->_cid == rEdge->_fromCid;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief checks if key and element match (_to case)
////////////////////////////////////////////////////////////////////////////////
static bool IsEqualKeyEdgeTo (TRI_multi_pointer_t* array,
void const* left,
void const* right) {
// left is a key
// right is an element, that is a master pointer
TRI_edge_header_t const* l;
TRI_doc_mptr_t const* rMptr;
TRI_doc_edge_key_marker_t const* rEdge;
const char* lKey;
const char* rKey;
l = left;
lKey = l->_key;
rMptr = right;
rEdge = rMptr->_data;
rKey = (char*) rEdge + rEdge->_offsetToKey;
return (strcmp(lKey, rKey) == 0) && l->_cid == rEdge->_toCid;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief checks for elements are equal (_from case)
////////////////////////////////////////////////////////////////////////////////
static bool IsEqualElementEdgeFrom (TRI_multi_pointer_t* array,
void const* left,
void const* right,
bool byKey) {
TRI_doc_mptr_t const* lMptr;
TRI_doc_mptr_t const* rMptr;
TRI_doc_edge_key_marker_t const* lEdge;
TRI_doc_edge_key_marker_t const* rEdge;
char const* lKey;
char const* rKey;
if (!byKey) {
return left == right;
}
else {
// only include directional flags, exclude special bits
return (l->_mptr == r->_mptr) &&
((l->_flags & TRI_EDGE_BITS_DIRECTION) ==
(r->_flags & TRI_EDGE_BITS_DIRECTION));
lMptr = left;
rMptr = right;
lEdge = lMptr->_data;
rEdge = rMptr->_data;
lKey = (char*) lEdge + lEdge->_offsetFromKey;
rKey = (char*) rEdge + rEdge->_offsetFromKey;
return strcmp(lKey, rKey) == 0 && lEdge->_fromCid == rEdge->_fromCid;
}
}
////////////////////////////////////////////////////////////////////////////////
/// @brief checks for elements are equal (_to case)
////////////////////////////////////////////////////////////////////////////////
static bool IsEqualElementEdgeTo (TRI_multi_pointer_t* array,
void const* left,
void const* right,
bool byKey) {
TRI_doc_mptr_t const* lMptr;
TRI_doc_mptr_t const* rMptr;
TRI_doc_edge_key_marker_t const* lEdge;
TRI_doc_edge_key_marker_t const* rEdge;
char const* lKey;
char const* rKey;
if (!byKey) {
return left == right;
}
else {
lMptr = left;
rMptr = right;
lEdge = lMptr->_data;
rEdge = rMptr->_data;
lKey = (char*) lEdge + lEdge->_offsetToKey;
rKey = (char*) rEdge + rEdge->_offsetToKey;
return strcmp(lKey, rKey) == 0 && lEdge->_toCid == rEdge->_toCid;
}
}
@ -814,42 +881,15 @@ static bool IsEqualElementEdge (TRI_multi_pointer_t* array,
static int InsertEdge (TRI_index_t* idx,
TRI_doc_mptr_t const* mptr,
const bool isRollback) {
TRI_edge_header_t* entryIn;
TRI_edge_header_t* entryOut;
char* memory;
TRI_doc_edge_key_marker_t const* edge;
bool isReflexive;
TRI_multi_pointer_t* edgesIndex = &(((TRI_edge_index_t*) idx)->_edges);
TRI_multi_pointer_t* edgesIndex;
edge = mptr->_data;
// is the edge self-reflexive (_from & _to are identical)?
isReflexive = (edge->_toCid == edge->_fromCid && strcmp(((char*) edge) + edge->_offsetToKey, ((char*) edge) + edge->_offsetFromKey) == 0);
// allocate memory for both edge headers and return early if memory allocation fails
memory = TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, 2 * sizeof(TRI_edge_header_t), false);
if (memory == NULL) {
return TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY);
}
entryIn = (TRI_edge_header_t*) memory;
entryOut = (TRI_edge_header_t*) (memory + sizeof(TRI_edge_header_t));
// first slot: IN
entryIn->_mptr = mptr;
entryIn->_flags = TRI_FlagsEdge(TRI_EDGE_IN, isReflexive);
entryIn->_cid = edge->_toCid;
entryIn->_searchKey._offsetKey = edge->_offsetToKey;
TRI_InsertElementMultiPointer(edgesIndex, entryIn, true, isRollback);
// second slot: OUT
entryOut->_mptr = mptr;
entryOut->_flags = TRI_FlagsEdge(TRI_EDGE_OUT, isReflexive);
entryOut->_cid = edge->_fromCid;
entryOut->_searchKey._offsetKey = edge->_offsetFromKey;
TRI_InsertElementMultiPointer(edgesIndex, entryOut, true, isRollback);
// OUT
edgesIndex = &(((TRI_edge_index_t*) idx)->_edges_from);
TRI_InsertElementMultiPointer(edgesIndex, CONST_CAST(mptr), true, isRollback);
// IN
edgesIndex = &(((TRI_edge_index_t*) idx)->_edges_to);
TRI_InsertElementMultiPointer(edgesIndex, CONST_CAST(mptr), true, isRollback);
return TRI_ERROR_NO_ERROR;
}
@ -859,34 +899,17 @@ static int InsertEdge (TRI_index_t* idx,
////////////////////////////////////////////////////////////////////////////////
static int RemoveEdge (TRI_index_t* idx,
TRI_doc_mptr_t const* doc,
TRI_doc_mptr_t const* mptr,
const bool isRollback) {
TRI_edge_header_t entry;
TRI_edge_header_t* old;
TRI_doc_edge_key_marker_t const* edge;
TRI_multi_pointer_t* edgesIndex = &(((TRI_edge_index_t*) idx)->_edges);
edge = doc->_data;
entry._mptr = doc;
TRI_multi_pointer_t* edgesIndex;
// OUT
entry._flags = TRI_LookupFlagsEdge(TRI_EDGE_OUT);
entry._cid = edge->_fromCid;
entry._searchKey._offsetKey = edge->_offsetFromKey;
TRI_RemoveElementMultiPointer(edgesIndex, &entry);
// we do not need to free the OUT element
edgesIndex = &(((TRI_edge_index_t*) idx)->_edges_from);
TRI_RemoveElementMultiPointer(edgesIndex, mptr);
// IN
entry._flags = TRI_LookupFlagsEdge(TRI_EDGE_IN);
entry._cid = edge->_toCid;
entry._searchKey._offsetKey = edge->_offsetToKey;
old = TRI_RemoveElementMultiPointer(edgesIndex, &entry);
// the pointer to the IN element is also the memory pointer we need to free
if (old != NULL) {
TRI_Free(TRI_UNKNOWN_MEM_ZONE, old);
}
edgesIndex = &(((TRI_edge_index_t*) idx)->_edges_from);
TRI_RemoveElementMultiPointer(edgesIndex, mptr);
return TRI_ERROR_NO_ERROR;
}
@ -920,14 +943,31 @@ static TRI_json_t* JsonEdge (TRI_index_t* idx) {
static int SizeHintEdge (TRI_index_t* idx,
size_t size) {
TRI_multi_pointer_t* edgesIndex = &(((TRI_edge_index_t*) idx)->_edges);
int err;
// we assume this is called when setting up the index and the index is still empty
TRI_multi_pointer_t* edgesIndex = &(((TRI_edge_index_t*) idx)->_edges_from);
// we assume this is called when setting up the index and the index
// is still empty
assert(edgesIndex->_nrUsed == 0);
// set an initial size for the index for some new nodes to be created
// without resizing, note we will put in two edge ends for each end.
return TRI_ResizeMultiPointer(edgesIndex, 2 * size + 2049);
// without resizing
err = TRI_ResizeMultiPointer(edgesIndex, size + 2049);
if (err != TRI_ERROR_NO_ERROR) {
return err;
}
edgesIndex = &(((TRI_edge_index_t*) idx)->_edges_to);
// we assume this is called when setting up the index and the index
// is still empty
assert(edgesIndex->_nrUsed == 0);
// set an initial size for the index for some new nodes to be created
// without resizing
return TRI_ResizeMultiPointer(edgesIndex, size + 2049);
}
////////////////////////////////////////////////////////////////////////////////
@ -961,19 +1001,31 @@ TRI_index_t* TRI_CreateEdgeIndex (struct TRI_primary_collection_s* primary,
return NULL;
}
res = TRI_InitMultiPointer(&edgeIndex->_edges,
res = TRI_InitMultiPointer(&edgeIndex->_edges_from,
TRI_UNKNOWN_MEM_ZONE,
HashElementKey,
HashElementEdge,
IsEqualKeyEdge,
IsEqualElementEdge);
HashElementEdgeFrom,
IsEqualKeyEdgeFrom,
IsEqualElementEdgeFrom);
if (res != TRI_ERROR_NO_ERROR) {
TRI_Free(TRI_CORE_MEM_ZONE, edgeIndex);
return NULL;
}
res = TRI_InitMultiPointer(&edgeIndex->_edges_to,
TRI_UNKNOWN_MEM_ZONE,
HashElementKey,
HashElementEdgeTo,
IsEqualKeyEdgeTo,
IsEqualElementEdgeTo);
if (res != TRI_ERROR_NO_ERROR) {
TRI_DestroyMultiPointer(&edgeIndex->_edges_from);
TRI_Free(TRI_CORE_MEM_ZONE, edgeIndex);
return NULL;
}
idx = &edgeIndex->base;
@ -998,38 +1050,13 @@ TRI_index_t* TRI_CreateEdgeIndex (struct TRI_primary_collection_s* primary,
void TRI_DestroyEdgeIndex (TRI_index_t* idx) {
TRI_edge_index_t* edgesIndex;
size_t i, n;
edgesIndex = (TRI_edge_index_t*) idx;
LOG_TRACE("destroying edge index");
// free all elements in the edges index
n = (size_t) edgesIndex->_edges._nrAlloc;
// deletion from the index is done in two steps as memory was only allocated for IN edges
// the OUT edges are at memory position IN + sizeof(edge_header) and
// must not be freed themselves
// step 1: zero out all the out edges (we must not free them directly)
for (i = 0; i < n; ++i) {
TRI_edge_header_t* element = edgesIndex->_edges._table[i].ptr;
if (element != NULL && (element->_flags & TRI_EDGE_BIT_DIRECTION_OUT)) {
edgesIndex->_edges._table[i].ptr = NULL;
}
}
// step 2: free the allocated memory
for (i = 0; i < n; ++i) {
TRI_edge_header_t* element = edgesIndex->_edges._table[i].ptr;
if (element != NULL) {
TRI_Free(TRI_UNKNOWN_MEM_ZONE, element);
}
}
TRI_DestroyMultiPointer(&edgesIndex->_edges);
TRI_DestroyMultiPointer(&edgesIndex->_edges_to);
TRI_DestroyMultiPointer(&edgesIndex->_edges_from);
TRI_DestroyVectorString(&idx->_fields);
}

View File

@ -185,7 +185,8 @@ TRI_geo_index_t;
typedef struct TRI_edge_index_s {
TRI_index_t base;
TRI_multi_pointer_t _edges;
TRI_multi_pointer_t _edges_from;
TRI_multi_pointer_t _edges_to;
}
TRI_edge_index_t;

View File

@ -283,8 +283,8 @@ static void HealHole (TRI_multi_pointer_t* array, uint64_t i) {
void* TRI_InsertElementMultiPointer (TRI_multi_pointer_t* array,
void* element,
const bool overwrite,
const bool checkEquality) {
bool const overwrite,
bool const checkEquality) {
// if the checkEquality flag is not set, we do not check for element
// equality we use this flag to speed up initial insertion into the

View File

@ -189,8 +189,8 @@ void* TRI_LookupByElementMultiPointer (TRI_multi_pointer_t*,
void* TRI_InsertElementMultiPointer (TRI_multi_pointer_t*,
void*,
const bool overwrite,
const bool checkEquality);
bool const overwrite,
bool const checkEquality);
////////////////////////////////////////////////////////////////////////////////
/// @brief removes an element from the array
@ -348,8 +348,8 @@ TRI_vector_pointer_t TRI_LookupByKeyMultiPointerKey (
void* TRI_InsertElementMultiPointerKey (TRI_multi_pointer_key_t*,
void* element,
void* key,
const bool overwrite,
const bool checkEquality);
bool const overwrite,
bool const checkEquality);
////////////////////////////////////////////////////////////////////////////////
/// @brief removes an element from the array