1
0
Fork 0

added linked list

This commit is contained in:
Frank Celler 2012-05-05 14:25:05 +02:00
parent 982e812679
commit f23e159a2a
10 changed files with 549 additions and 31 deletions

View File

@ -296,6 +296,7 @@ bool TRI_InsertElementAssociativeArray (TRI_associative_array_t* array, void* el
// check for out-of-memory
if (array->_nrAlloc == array->_nrUsed) {
TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY);
return false;
}
@ -344,6 +345,7 @@ bool TRI_InsertKeyAssociativeArray (TRI_associative_array_t* array, void* key, v
// check for out-of-memory
if (array->_nrAlloc == array->_nrUsed) {
TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY);
return false;
}
@ -684,8 +686,8 @@ bool TRI_EqualStringKeyAssociativePointer (TRI_associative_pointer_t* array,
/// @brief lookups an element given a key
////////////////////////////////////////////////////////////////////////////////
void const* TRI_LookupByKeyAssociativePointer (TRI_associative_pointer_t* array,
void const* key) {
void* TRI_LookupByKeyAssociativePointer (TRI_associative_pointer_t* array,
void const* key) {
uint64_t hash;
uint64_t i;
@ -710,8 +712,8 @@ void const* TRI_LookupByKeyAssociativePointer (TRI_associative_pointer_t* array,
/// @brief lookups an element given an element
////////////////////////////////////////////////////////////////////////////////
void const* TRI_LookupByElementAssociativePointer (TRI_associative_pointer_t* array,
void const* element) {
void* TRI_LookupByElementAssociativePointer (TRI_associative_pointer_t* array,
void const* element) {
uint64_t hash;
uint64_t i;
@ -745,6 +747,7 @@ void* TRI_InsertElementAssociativePointer (TRI_associative_pointer_t* array,
// check for out-of-memory
if (array->_nrAlloc == array->_nrUsed) {
TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY);
return NULL;
}
@ -798,7 +801,8 @@ void* TRI_InsertKeyAssociativePointer (TRI_associative_pointer_t* array,
// check for out-of-memory
if (array->_nrAlloc == array->_nrUsed) {
return false;
TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY);
return NULL;
}
// compute the hash
@ -1185,7 +1189,8 @@ void* TRI_InsertElementAssociativeSynced (TRI_associative_synced_t* array,
// check for out-of-memory
if (array->_nrAlloc == array->_nrUsed) {
return false;
TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY);
return NULL;
}
// compute the hash
@ -1237,7 +1242,8 @@ void* TRI_InsertKeyAssociativeSynced (TRI_associative_synced_t* array,
// check for out-of-memory
if (array->_nrAlloc == array->_nrUsed) {
return false;
TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY);
return NULL;
}
// compute the hash

View File

@ -304,13 +304,13 @@ bool TRI_EqualStringKeyAssociativePointer (TRI_associative_pointer_t*, void cons
/// @brief lookups an element given a key
////////////////////////////////////////////////////////////////////////////////
void const* TRI_LookupByKeyAssociativePointer (TRI_associative_pointer_t*, void const* key);
void* TRI_LookupByKeyAssociativePointer (TRI_associative_pointer_t*, void const* key);
////////////////////////////////////////////////////////////////////////////////
/// @brief lookups an element given an element
////////////////////////////////////////////////////////////////////////////////
void const* TRI_LookupByElementAssociativePointer (TRI_associative_pointer_t*, void const* element);
void* TRI_LookupByElementAssociativePointer (TRI_associative_pointer_t*, void const* element);
////////////////////////////////////////////////////////////////////////////////
/// @brief adds an element to the array

294
BasicsC/linked-list.c Normal file
View File

@ -0,0 +1,294 @@
////////////////////////////////////////////////////////////////////////////////
/// @brief linked list implementation
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2012 triagens GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is triAGENS GmbH, Cologne, Germany
///
/// @author Dr. Frank Celler
/// @author Copyright 2012, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
#include "linked-list.h"
// -----------------------------------------------------------------------------
// --SECTION-- LINKED LIST
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// --SECTION-- private functions
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup Collections
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief hash key
////////////////////////////////////////////////////////////////////////////////
uint64_t HashKey (TRI_associative_pointer_t* array, void const* key) {
return (uint64_t) (intptr_t) key;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief hash element
////////////////////////////////////////////////////////////////////////////////
uint64_t HashElement (TRI_associative_pointer_t* array, void const* element) {
TRI_linked_list_entry_t const* entry = element;
return (uint64_t) (intptr_t) entry->_data;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief equal key
////////////////////////////////////////////////////////////////////////////////
bool EqualKey (TRI_associative_pointer_t* array, void const* key, void const* element) {
TRI_linked_list_entry_t const* entry = element;
return key == entry->_data;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief equal element
////////////////////////////////////////////////////////////////////////////////
bool EqualElement (TRI_associative_pointer_t* array, void const* left, void const* right) {
TRI_linked_list_entry_t const* l = left;
TRI_linked_list_entry_t const* r = right;
return l->_data == r->_data;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief equal element
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- constructors and destructors
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup Collections
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief inits a linked list
////////////////////////////////////////////////////////////////////////////////
void TRI_InitLinkedList (TRI_linked_list_t* list, TRI_memory_zone_t* zone) {
list->_memoryZone = zone;
list->_begin = NULL;
list->_end = NULL;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief inits a linked array
////////////////////////////////////////////////////////////////////////////////
void TRI_InitLinkedArray (TRI_linked_array_t* array, TRI_memory_zone_t* zone) {
array->_memoryZone = zone;
TRI_InitLinkedList(&array->_list, zone);
TRI_InitAssociativePointer(&array->_array,
zone,
HashKey,
HashElement,
EqualKey,
EqualElement);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief destroys a linked list, but does not free the pointer
////////////////////////////////////////////////////////////////////////////////
void TRI_DestroyLinkedList (TRI_linked_list_t* list) {
// nothing to destroy
}
////////////////////////////////////////////////////////////////////////////////
/// @brief destroys a linked list and frees the pointer
////////////////////////////////////////////////////////////////////////////////
void TRI_FreeLinkedList (TRI_memory_zone_t* zone, TRI_linked_list_t* list) {
TRI_DestroyLinkedList(list);
TRI_Free(zone, list);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief destroys a linked array, but does not free the pointer
////////////////////////////////////////////////////////////////////////////////
void TRI_DestroyLinkedArray (TRI_linked_array_t* array) {
TRI_DestroyLinkedList(&array->_list);
TRI_DestroyAssociativePointer(&array->_array);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief destroys a linked list and frees the pointer
////////////////////////////////////////////////////////////////////////////////
void TRI_FreeLinkedArray (TRI_memory_zone_t* zone, TRI_linked_array_t* array) {
TRI_DestroyLinkedList(&array->_list);
TRI_Free(zone, array);
}
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- public methods
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup Collections
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief inserts an entry at the end of a linked list
////////////////////////////////////////////////////////////////////////////////
void TRI_AddLinkedList (TRI_linked_list_t* list, TRI_linked_list_entry_t* entry) {
if (list->_end == NULL) {
entry->_next = NULL;
entry->_prev = NULL;
list->_begin = entry;
list->_end = entry;
}
else {
entry->_next = NULL;
entry->_prev = list->_end;
list->_end->_next = entry;
list->_end = entry;
}
}
////////////////////////////////////////////////////////////////////////////////
/// @brief removes an entry from a linked list
////////////////////////////////////////////////////////////////////////////////
void TRI_RemoveLinkedList (TRI_linked_list_t* list, TRI_linked_list_entry_t* entry) {
// element is at the beginning of the chain
if (entry->_prev == NULL) {
list->_begin = entry->_next;
}
else {
entry->_prev->_next = entry->_next;
}
// element is at the end of the chain
if (entry->_next == NULL) {
list->_end = entry->_prev;
}
else {
entry->_next->_prev = entry->_prev;
}
}
////////////////////////////////////////////////////////////////////////////////
/// @brief inserts an entry at the end of a linked array
////////////////////////////////////////////////////////////////////////////////
int TRI_AddLinkedArray (TRI_linked_array_t* array, void const* data) {
TRI_linked_list_entry_t* entry;
TRI_linked_list_entry_t* found;
// create entry
entry = TRI_Allocate(array->_memoryZone, sizeof(TRI_linked_list_entry_t), false);
if (entry == NULL) {
return TRI_ERROR_OUT_OF_MEMORY;
}
entry->_data = data;
// insert to lookup table
found = TRI_InsertElementAssociativePointer(&array->_array, entry, true);
if (TRI_errno() == TRI_ERROR_OUT_OF_MEMORY) {
TRI_Free(array->_memoryZone, entry);
return TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY);
}
// this should not happen
if (found != NULL) {
TRI_RemoveLinkedList(&array->_list, found);
TRI_Free(array->_memoryZone, found);
}
// add element at the beginning
TRI_AddLinkedList(&array->_list, entry);
return TRI_ERROR_NO_ERROR;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief removes an entry from a linked array
////////////////////////////////////////////////////////////////////////////////
void TRI_RemoveLinkedArray (TRI_linked_array_t* array, void const* data) {
TRI_linked_list_entry_t* found;
found = TRI_RemoveKeyAssociativePointer(&array->_array, data);
if (found != NULL) {
TRI_RemoveLinkedList(&array->_list, found);
}
TRI_Free(array->_memoryZone, found);
}
////////////////////////////////////////////////////////////////////////////////
/// @brief moves an entry to the end of a linked array
////////////////////////////////////////////////////////////////////////////////
void TRI_MoveToBackLinkedArray (TRI_linked_array_t* array, void const* data) {
TRI_linked_list_entry_t* found;
found = TRI_LookupByKeyAssociativePointer(&array->_array, data);
if (found) {
if (found->_next != NULL) {
TRI_RemoveLinkedList(&array->_list, found);
TRI_AddLinkedList(&array->_list, found);
}
}
}
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// Local Variables:
// mode: outline-minor
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)"
// End:

190
BasicsC/linked-list.h Normal file
View File

@ -0,0 +1,190 @@
////////////////////////////////////////////////////////////////////////////////
/// @brief linked list implementation
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2012 triagens GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is triAGENS GmbH, Cologne, Germany
///
/// @author Dr. Frank Celler
/// @author Copyright 2012, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////
#ifndef TRIAGENS_BASICS_C_LINKED_LIST_H
#define TRIAGENS_BASICS_C_LINKED_LIST_H 1
#include "BasicsC/common.h"
#include "BasicsC/associative.h"
#ifdef __cplusplus
extern "C" {
#endif
// -----------------------------------------------------------------------------
// --SECTION-- LINKED LIST
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// --SECTION-- public types
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup Collections
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief linked list entry
////////////////////////////////////////////////////////////////////////////////
typedef struct TRI_linked_list_entry_s {
void const* _data;
struct TRI_linked_list_entry_s* _prev;
struct TRI_linked_list_entry_s* _next;
}
TRI_linked_list_entry_t;
////////////////////////////////////////////////////////////////////////////////
/// @brief linked list
////////////////////////////////////////////////////////////////////////////////
typedef struct TRI_linked_list_s {
TRI_memory_zone_t* _memoryZone;
TRI_linked_list_entry_t* _begin;
TRI_linked_list_entry_t* _end;
}
TRI_linked_list_t;
////////////////////////////////////////////////////////////////////////////////
/// @brief linked array
////////////////////////////////////////////////////////////////////////////////
typedef struct TRI_linked_array_s {
TRI_memory_zone_t* _memoryZone;
TRI_linked_list_t _list;
TRI_associative_pointer_t _array;
}
TRI_linked_array_t;
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- constructors and destructors
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup Collections
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief inits a linked list
////////////////////////////////////////////////////////////////////////////////
void TRI_InitLinkedList (TRI_linked_list_t*, TRI_memory_zone_t*);
////////////////////////////////////////////////////////////////////////////////
/// @brief inits a linked array
////////////////////////////////////////////////////////////////////////////////
void TRI_InitLinkedArray (TRI_linked_array_t*, TRI_memory_zone_t*);
////////////////////////////////////////////////////////////////////////////////
/// @brief destroys a linked list, but does not free the pointer
////////////////////////////////////////////////////////////////////////////////
void TRI_DestroyLinkedList (TRI_linked_list_t*);
////////////////////////////////////////////////////////////////////////////////
/// @brief destroys a linked list and frees the pointer
////////////////////////////////////////////////////////////////////////////////
void TRI_FreeLinkedList (TRI_memory_zone_t*, TRI_linked_list_t*);
////////////////////////////////////////////////////////////////////////////////
/// @brief destroys a linked array, but does not free the pointer
////////////////////////////////////////////////////////////////////////////////
void TRI_DestroyLinkedArray (TRI_linked_array_t*);
////////////////////////////////////////////////////////////////////////////////
/// @brief destroys a linked list and frees the pointer
////////////////////////////////////////////////////////////////////////////////
void TRI_FreeLinkedArray (TRI_memory_zone_t*, TRI_linked_array_t*);
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// --SECTION-- public methods
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
/// @addtogroup Collections
/// @{
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
/// @brief inserts an entry at the end of a linked list
////////////////////////////////////////////////////////////////////////////////
void TRI_AddLinkedList (TRI_linked_list_t*, TRI_linked_list_entry_t*);
////////////////////////////////////////////////////////////////////////////////
/// @brief removes an entry from a linked list
////////////////////////////////////////////////////////////////////////////////
void TRI_RemoveLinkedList (TRI_linked_list_t*, TRI_linked_list_entry_t*);
////////////////////////////////////////////////////////////////////////////////
/// @brief inserts an entry at the end of a linked array
////////////////////////////////////////////////////////////////////////////////
int TRI_AddLinkedArray (TRI_linked_array_t*, void const* data);
////////////////////////////////////////////////////////////////////////////////
/// @brief removes an entry from a linked array
////////////////////////////////////////////////////////////////////////////////
void TRI_RemoveLinkedArray (TRI_linked_array_t*, void const* data);
////////////////////////////////////////////////////////////////////////////////
/// @brief moves an entry to the end of a linked array
////////////////////////////////////////////////////////////////////////////////
void TRI_MoveToBackLinkedArray (TRI_linked_array_t* array, void const* data);
////////////////////////////////////////////////////////////////////////////////
/// @}
////////////////////////////////////////////////////////////////////////////////
#ifdef __cplusplus
}
#endif
#endif
// Local Variables:
// mode: outline-minor
// outline-regexp: "^\\(/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|// --SECTION--\\|/// @\\}\\)"
// End:

View File

@ -32,6 +32,7 @@ libavocado_a_SOURCES = \
BasicsC/hashes.c \
BasicsC/init.c \
BasicsC/json.c \
BasicsC/linked-list.c \
BasicsC/locks-macos.c \
BasicsC/locks-posix.c \
BasicsC/logging.c \

View File

@ -199,8 +199,9 @@ am__libavocado_a_SOURCES_DIST = Basics/ConditionLocker.cpp \
BasicsC/associative-multi.c BasicsC/associative.c \
BasicsC/conversions.c BasicsC/csv.c BasicsC/error.c \
BasicsC/files.c BasicsC/hashes.c BasicsC/init.c BasicsC/json.c \
BasicsC/locks-macos.c BasicsC/locks-posix.c BasicsC/logging.c \
BasicsC/memory.c BasicsC/process-utils.c BasicsC/random.c \
BasicsC/linked-list.c BasicsC/locks-macos.c \
BasicsC/locks-posix.c BasicsC/logging.c BasicsC/memory.c \
BasicsC/process-utils.c BasicsC/random.c \
BasicsC/socket-utils.c BasicsC/string-buffer.c \
BasicsC/strings.c BasicsC/structures.c \
BasicsC/system-functions.c BasicsC/terminal-utils-ncurses.c \
@ -253,11 +254,12 @@ am_libavocado_a_OBJECTS = Basics/ConditionLocker.$(OBJEXT) \
BasicsC/csv.$(OBJEXT) BasicsC/error.$(OBJEXT) \
BasicsC/files.$(OBJEXT) BasicsC/hashes.$(OBJEXT) \
BasicsC/init.$(OBJEXT) BasicsC/json.$(OBJEXT) \
BasicsC/locks-macos.$(OBJEXT) BasicsC/locks-posix.$(OBJEXT) \
BasicsC/logging.$(OBJEXT) BasicsC/memory.$(OBJEXT) \
BasicsC/process-utils.$(OBJEXT) BasicsC/random.$(OBJEXT) \
BasicsC/socket-utils.$(OBJEXT) BasicsC/string-buffer.$(OBJEXT) \
BasicsC/strings.$(OBJEXT) BasicsC/structures.$(OBJEXT) \
BasicsC/linked-list.$(OBJEXT) BasicsC/locks-macos.$(OBJEXT) \
BasicsC/locks-posix.$(OBJEXT) BasicsC/logging.$(OBJEXT) \
BasicsC/memory.$(OBJEXT) BasicsC/process-utils.$(OBJEXT) \
BasicsC/random.$(OBJEXT) BasicsC/socket-utils.$(OBJEXT) \
BasicsC/string-buffer.$(OBJEXT) BasicsC/strings.$(OBJEXT) \
BasicsC/structures.$(OBJEXT) \
BasicsC/system-functions.$(OBJEXT) \
BasicsC/terminal-utils-ncurses.$(OBJEXT) \
BasicsC/terminal-utils.$(OBJEXT) \
@ -748,8 +750,9 @@ libavocado_a_SOURCES = Basics/ConditionLocker.cpp \
BasicsC/associative-multi.c BasicsC/associative.c \
BasicsC/conversions.c BasicsC/csv.c BasicsC/error.c \
BasicsC/files.c BasicsC/hashes.c BasicsC/init.c BasicsC/json.c \
BasicsC/locks-macos.c BasicsC/locks-posix.c BasicsC/logging.c \
BasicsC/memory.c BasicsC/process-utils.c BasicsC/random.c \
BasicsC/linked-list.c BasicsC/locks-macos.c \
BasicsC/locks-posix.c BasicsC/logging.c BasicsC/memory.c \
BasicsC/process-utils.c BasicsC/random.c \
BasicsC/socket-utils.c BasicsC/string-buffer.c \
BasicsC/strings.c BasicsC/structures.c \
BasicsC/system-functions.c BasicsC/terminal-utils-ncurses.c \
@ -1250,6 +1253,8 @@ BasicsC/init.$(OBJEXT): BasicsC/$(am__dirstamp) \
BasicsC/$(DEPDIR)/$(am__dirstamp)
BasicsC/json.$(OBJEXT): BasicsC/$(am__dirstamp) \
BasicsC/$(DEPDIR)/$(am__dirstamp)
BasicsC/linked-list.$(OBJEXT): BasicsC/$(am__dirstamp) \
BasicsC/$(DEPDIR)/$(am__dirstamp)
BasicsC/locks-macos.$(OBJEXT): BasicsC/$(am__dirstamp) \
BasicsC/$(DEPDIR)/$(am__dirstamp)
BasicsC/locks-posix.$(OBJEXT): BasicsC/$(am__dirstamp) \
@ -2074,6 +2079,7 @@ mostlyclean-compile:
-rm -f BasicsC/hashes.$(OBJEXT)
-rm -f BasicsC/init.$(OBJEXT)
-rm -f BasicsC/json.$(OBJEXT)
-rm -f BasicsC/linked-list.$(OBJEXT)
-rm -f BasicsC/locks-macos.$(OBJEXT)
-rm -f BasicsC/locks-posix.$(OBJEXT)
-rm -f BasicsC/logging.$(OBJEXT)
@ -2318,6 +2324,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@BasicsC/$(DEPDIR)/hashes.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@BasicsC/$(DEPDIR)/init.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@BasicsC/$(DEPDIR)/json.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@BasicsC/$(DEPDIR)/linked-list.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@BasicsC/$(DEPDIR)/locks-macos.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@BasicsC/$(DEPDIR)/locks-posix.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@BasicsC/$(DEPDIR)/logging.Po@am__quote@

View File

@ -82,7 +82,8 @@ TRI_barrier_t* TRI_CreateBarrierElement (TRI_barrier_list_t* container) {
TRI_barrier_t* element;
element = TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_barrier_t), false);
if (!element) {
if (element == NULL) {
return NULL;
}

View File

@ -89,8 +89,9 @@ static TRI_doc_mptr_t* RequestSimpleHeaders (TRI_headers_t* h) {
char* ptr;
begin = TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, NUMBER_HEADERS_PER_BLOCK * headers->_headerSize, false);
// out of memory
if (!begin) {
// out of memory
TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY);
return NULL;
}

View File

@ -27,16 +27,16 @@
#include "index.h"
#include <BasicsC/conversions.h>
#include <BasicsC/files.h>
#include <BasicsC/json.h>
#include <BasicsC/logging.h>
#include <BasicsC/string-buffer.h>
#include <BasicsC/strings.h>
#include <VocBase/simple-collection.h>
#include "ShapedJson/shaped-json.h"
#include "BasicsC/conversions.h"
#include "BasicsC/files.h"
#include "BasicsC/json.h"
#include "BasicsC/linked-list.h"
#include "BasicsC/logging.h"
#include "BasicsC/string-buffer.h"
#include "BasicsC/strings.h"
#include "ShapedJson/shape-accessor.h"
#include "ShapedJson/shaped-json.h"
#include "VocBase/simple-collection.h"
// -----------------------------------------------------------------------------
// --SECTION-- INDEX
@ -318,7 +318,7 @@ static TRI_json_t* JsonCapConstraint (TRI_index_t* idx, TRI_doc_collection_t con
}
////////////////////////////////////////////////////////////////////////////////
/// @brief describes a cap constraint as a json object
/// @brief removes a cap constraint from collection
////////////////////////////////////////////////////////////////////////////////
static void RemoveIndexCapConstraint (TRI_index_t* idx, TRI_doc_collection_t* collection) {
@ -330,7 +330,11 @@ static void RemoveIndexCapConstraint (TRI_index_t* idx, TRI_doc_collection_t* co
////////////////////////////////////////////////////////////////////////////////
static int InsertCapConstraint (TRI_index_t* idx, TRI_doc_mptr_t const* doc) {
return TRI_ERROR_NO_ERROR;
TRI_cap_constraint_t* cap;
cap = (TRI_cap_constraint_t*) idx;
return TRI_AddLinkedArray(&cap->_array, doc);
}
////////////////////////////////////////////////////////////////////////////////
@ -340,6 +344,11 @@ static int InsertCapConstraint (TRI_index_t* idx, TRI_doc_mptr_t const* doc) {
static int UpdateCapConstraint (TRI_index_t* idx,
const TRI_doc_mptr_t* newDoc,
const TRI_shaped_json_t* oldDoc) {
TRI_cap_constraint_t* cap;
cap = (TRI_cap_constraint_t*) idx;
TRI_MoveToBackLinkedArray(&cap->_array, newDoc);
return TRI_ERROR_NO_ERROR;
}
@ -348,6 +357,11 @@ static int UpdateCapConstraint (TRI_index_t* idx,
////////////////////////////////////////////////////////////////////////////////
static int RemoveCapConstraint (TRI_index_t* idx, TRI_doc_mptr_t const* doc) {
TRI_cap_constraint_t* cap;
cap = (TRI_cap_constraint_t*) idx;
TRI_RemoveLinkedArray(&cap->_array, doc);
return TRI_ERROR_NO_ERROR;
}
@ -386,6 +400,8 @@ TRI_index_t* TRI_CreateCapConstraint (struct TRI_doc_collection_s* collection,
cap->base.update = UpdateCapConstraint;
cap->base.remove = RemoveCapConstraint;
TRI_InitLinkedArray(&cap->_array, TRI_UNKNOWN_MEM_ZONE);
cap->_size = size;
return &cap->base;

View File

@ -31,6 +31,7 @@
#include "VocBase/vocbase.h"
#include "BasicsC/json.h"
#include "BasicsC/linked-list.h"
#include "ShapedJson/shaped-json.h"
#include "GeoIndex/GeoIndex.h"
#include "HashIndex/hashindex.h"
@ -178,6 +179,7 @@ TRI_skiplist_index_t;
typedef struct TRI_cap_constraint_s {
TRI_index_t base;
TRI_linked_array_t _array;
size_t _size;
}
TRI_cap_constraint_t;