TRI_json_t* TRI_LookupArrayJson (const TRI_json_t* const object, char const* name) { size_t i, n; if (object == NULL) { return NULL; } TRI_ASSERT(object->_type == TRI_JSON_ARRAY); TRI_ASSERT(name != NULL); n = object->_value._objects._length; for (i = 0; i < n; i += 2) { TRI_json_t* key; key = (TRI_json_t*) TRI_AtVector(&object->_value._objects, i); if (! IsString(key)) { continue; } if (TRI_EqualString(key->_value._string.data, name)) { return (TRI_json_t*) TRI_AtVector(&object->_value._objects, i + 1); } } return NULL; }
TRI_json_t* TRI_LookupArrayJson (TRI_json_t* object, char const* name) { size_t n; size_t i; assert(object->_type == TRI_JSON_ARRAY); assert(name); n = object->_value._objects._length; for (i = 0; i < n; i += 2) { TRI_json_t* key; key = TRI_AtVector(&object->_value._objects, i); if (key->_type != TRI_JSON_STRING) { continue; } if (TRI_EqualString(key->_value._string.data, name)) { return TRI_AtVector(&object->_value._objects, i + 1); } } return NULL; }
bool TRI_HasDuplicateKeyJson (const TRI_json_t* const object) { if (object && object->_type == TRI_JSON_ARRAY) { size_t n; // if we don't have attributes, we do not need to check for duplicates // if we only have one attribute, we don't need to check for duplicates in // the array, but we need to recursively validate the array values (if // array value itself is an array) n = object->_value._objects._length; if (n > 0) { TRI_associative_pointer_t hash; size_t i; TRI_InitAssociativePointer(&hash, TRI_UNKNOWN_MEM_ZONE, &TRI_HashStringKeyAssociativePointer, &TRI_HashStringKeyAssociativePointer, &TRI_EqualStringKeyAssociativePointer, 0); for (i = 0; i < n; i += 2) { TRI_json_t* key; TRI_json_t* value; void* previous; key = TRI_AtVector(&object->_value._objects, i); if (key->_type != TRI_JSON_STRING) { continue; } value = TRI_AtVector(&object->_value._objects, i + 1); // recursively check sub-array elements if (value->_type == TRI_JSON_ARRAY && TRI_HasDuplicateKeyJson(value)) { // duplicate found in sub-array TRI_DestroyAssociativePointer(&hash); return true; } previous = TRI_InsertKeyAssociativePointer(&hash, key->_value._string.data, key->_value._string.data, false); if (previous != NULL) { // duplicate found TRI_DestroyAssociativePointer(&hash); return true; } } TRI_DestroyAssociativePointer(&hash); } } // no duplicate found return false; }
static TRI_json_t* MergeRecursive (TRI_memory_zone_t* zone, const TRI_json_t* const lhs, const TRI_json_t* const rhs, const bool nullMeansRemove) { size_t i, n; TRI_json_t* result = TRI_CopyJson(zone, lhs); if (result == NULL) { return NULL; } n = rhs->_value._objects._length; for (i = 0; i < n; i += 2) { // enumerate all the replacement values TRI_json_t* key = TRI_AtVector(&rhs->_value._objects, i); TRI_json_t* value = TRI_AtVector(&rhs->_value._objects, i + 1); if (value->_type == TRI_JSON_NULL && nullMeansRemove) { // replacement value is a null and we don't want to store nulls => delete attribute from the result TRI_DeleteArrayJson(zone, result, key->_value._string.data); } else { // replacement value is not a null or we want to store nulls TRI_json_t* lhsValue = TRI_LookupArrayJson(lhs, key->_value._string.data); if (lhsValue == NULL) { // existing array does not have the attribute => append new attribute if (value->_type == TRI_JSON_ARRAY) { TRI_json_t* empty = TRI_CreateArrayJson(zone); TRI_json_t* merged = MergeRecursive(zone, empty, value, nullMeansRemove); TRI_Insert3ArrayJson(zone, result, key->_value._string.data, merged); TRI_FreeJson(zone, empty); } else { TRI_Insert3ArrayJson(zone, result, key->_value._string.data, TRI_CopyJson(zone, value)); } } else { // existing array already has the attribute => replace attribute if (lhsValue->_type == TRI_JSON_ARRAY && value->_type == TRI_JSON_ARRAY) { TRI_json_t* merged = MergeRecursive(zone, lhsValue, value, nullMeansRemove); TRI_ReplaceArrayJson(zone, result, key->_value._string.data, merged); TRI_FreeJson(zone, merged); } else { TRI_ReplaceArrayJson(zone, result, key->_value._string.data, value); } } } } return result; }
int TRI_CopyToJson (TRI_memory_zone_t* zone, TRI_json_t* dst, TRI_json_t const* src) { int res; size_t n; size_t i; dst->_type = src->_type; switch (src->_type) { case TRI_JSON_UNUSED: case TRI_JSON_NULL: break; case TRI_JSON_BOOLEAN: dst->_value._boolean = src->_value._boolean; break; case TRI_JSON_NUMBER: dst->_value._number = src->_value._number; break; case TRI_JSON_STRING: return TRI_CopyToBlob(zone, &dst->_value._string, &src->_value._string); case TRI_JSON_STRING_REFERENCE: return TRI_AssignToBlob(zone, &dst->_value._string, &src->_value._string); case TRI_JSON_ARRAY: case TRI_JSON_LIST: n = src->_value._objects._length; TRI_InitVector(&dst->_value._objects, zone, sizeof(TRI_json_t)); res = TRI_ResizeVector(&dst->_value._objects, n); if (res != TRI_ERROR_NO_ERROR) { return res; } for (i = 0; i < n; ++i) { TRI_json_t const* v = static_cast<TRI_json_t const*>(TRI_AtVector(&src->_value._objects, i)); TRI_json_t* w = static_cast<TRI_json_t*>(TRI_AtVector(&dst->_value._objects, i)); res = TRI_CopyToJson(zone, w, v); if (res != TRI_ERROR_NO_ERROR) { return res; } } break; } return TRI_ERROR_NO_ERROR; }
void TRI_DestroyJson (TRI_memory_zone_t* zone, TRI_json_t* object) { switch (object->_type) { case TRI_JSON_UNUSED: case TRI_JSON_NULL: case TRI_JSON_BOOLEAN: case TRI_JSON_NUMBER: break; case TRI_JSON_STRING: TRI_DestroyBlob(zone, &object->_value._string); break; case TRI_JSON_STRING_REFERENCE: // we will not be destroying the string!! break; case TRI_JSON_ARRAY: case TRI_JSON_LIST: { size_t i, n; n = object->_value._objects._length; for (i = 0; i < n; ++i) { TRI_json_t* v = (TRI_json_t*) TRI_AtVector(&object->_value._objects, i); TRI_DestroyJson(zone, v); } TRI_DestroyVector(&object->_value._objects); break; } } }
TRI_json_t* TRI_UniquifyListJson (const TRI_json_t* const list) { TRI_json_t* last = NULL; TRI_json_t* result; size_t i, n; assert(list); assert(list->_type == TRI_JSON_LIST); // create result list result = TRI_CreateListJson(TRI_UNKNOWN_MEM_ZONE); if (!result) { return NULL; } n = list->_value._objects._length; for (i = 0; i < n; ++i) { TRI_json_t* p = TRI_AtVector(&list->_value._objects, i); // don't push value if it is the same as the last value if (!last || TRI_CompareValuesJson(p, last) > 0) { TRI_PushBackListJson(TRI_UNKNOWN_MEM_ZONE, result, p); // remember last element last = p; } } return result; }
TRI_json_t* TRI_UniquifyArrayJson (TRI_json_t const* array) { TRI_ASSERT(array != nullptr); TRI_ASSERT(array->_type == TRI_JSON_ARRAY); // create result array std::unique_ptr<TRI_json_t> result(TRI_CreateArrayJson(TRI_UNKNOWN_MEM_ZONE)); if (result == nullptr) { return nullptr; } size_t const n = TRI_LengthVector(&array->_value._objects); TRI_json_t const* last = nullptr; for (size_t i = 0; i < n; ++i) { auto p = static_cast<TRI_json_t const*>(TRI_AtVector(&array->_value._objects, i)); // don't push value if it is the same as the last value if (last == nullptr || TRI_CompareValuesJson(p, last, false) != 0) { TRI_PushBackArrayJson(TRI_UNKNOWN_MEM_ZONE, result.get(), p); // remember last element last = p; } } return result.release(); }
static bool CheckAndLockCompaction (TRI_vocbase_t* vocbase) { double now; size_t i, n; now = TRI_microtime(); // check if we can acquire the write lock instantly if (! TryLockCompaction(vocbase)) { // couldn't acquire the write lock return false; } // we are now holding the write lock // check if we have a still-valid compaction blocker n = vocbase->_compactionBlockers._data._length; for (i = 0; i < n; ++i) { compaction_blocker_t* blocker = TRI_AtVector(&vocbase->_compactionBlockers._data, i); if (blocker->_expires > now) { // found a compaction blocker. unlock and return UnlockCompaction(vocbase); return false; } } return true; }
int TRI_TouchBlockerCompactorVocBase (TRI_vocbase_t* vocbase, TRI_voc_tick_t id, double lifetime) { size_t i, n; bool found; found = false; if (lifetime <= 0.0) { return TRI_ERROR_BAD_PARAMETER; } LockCompaction(vocbase); n = vocbase->_compactionBlockers._data._length; for (i = 0; i < n; ++i) { compaction_blocker_t* blocker = TRI_AtVector(&vocbase->_compactionBlockers._data, i); if (blocker->_id == id) { blocker->_expires = TRI_microtime() + lifetime; found = true; break; } } UnlockCompaction(vocbase); if (! found) { return TRI_ERROR_ARANGO_DOCUMENT_NOT_FOUND; } return TRI_ERROR_NO_ERROR; }
bool TRI_CleanupCompactorVocBase (TRI_vocbase_t* vocbase) { double now; size_t i, n; now = TRI_microtime(); // check if we can instantly acquire the lock if (! TryLockCompaction(vocbase)) { // couldn't acquire lock return false; } // we are now holding the write lock n = vocbase->_compactionBlockers._data._length; i = 0; while (i < n) { compaction_blocker_t* blocker = TRI_AtVector(&vocbase->_compactionBlockers._data, i); if (blocker->_expires < now) { TRI_RemoveVector(&vocbase->_compactionBlockers._data, i); n--; } else { i++; } } UnlockCompaction(vocbase); return true; }
int TRI_RemoveBlockerCompactorVocBase (TRI_vocbase_t* vocbase, TRI_voc_tick_t id) { size_t i, n; bool found; found = false; LockCompaction(vocbase); n = vocbase->_compactionBlockers._data._length; for (i = 0; i < n; ++i) { compaction_blocker_t* blocker = TRI_AtVector(&vocbase->_compactionBlockers._data, i); if (blocker->_id == id) { TRI_RemoveVector(&vocbase->_compactionBlockers._data, i); found = true; break; } } UnlockCompaction(vocbase); if (! found) { return TRI_ERROR_ARANGO_DOCUMENT_NOT_FOUND; } return TRI_ERROR_NO_ERROR; }
void TRI_DestroyJson (TRI_memory_zone_t* zone, TRI_json_t* object) { size_t n; size_t i; switch (object->_type) { case TRI_JSON_UNUSED: case TRI_JSON_NULL: case TRI_JSON_BOOLEAN: case TRI_JSON_NUMBER: break; case TRI_JSON_STRING: TRI_DestroyBlob(zone, &object->_value._string); break; case TRI_JSON_ARRAY: case TRI_JSON_LIST: n = object->_value._objects._length; for (i = 0; i < n; ++i) { TRI_json_t* v = TRI_AtVector(&object->_value._objects, i); TRI_DestroyJson(zone, v); } TRI_DestroyVector(&object->_value._objects); break; } }
void* BitarrayIndexNextIterationCallback(TRI_index_iterator_t* iterator) { TRI_index_iterator_interval_t* interval; iterator->_currentDocument = NULL; if (iterator->_cursor == NULL) { iterator->_currentInterval = 0; } if (iterator->_intervals._length == 0) { return NULL; } if (iterator->_currentInterval >= iterator->_intervals._length) { return NULL; } interval = (TRI_index_iterator_interval_t*)(TRI_AtVector(&(iterator->_intervals),iterator->_currentInterval)); if (interval == NULL) { // should not occur -- something is wrong LOG_WARNING("internal error in BitarrayIndexNextIterationCallback"); return NULL; } iterator->_cursor = interval->_leftEndPoint; iterator->_currentDocument = interval->_leftEndPoint; ++iterator->_currentInterval; return iterator->_currentDocument; }
bool TRI_AddParameterValuesAql (TRI_aql_context_t* const context, const TRI_json_t* const parameters) { size_t i; size_t n; assert(context); if (parameters == NULL) { // no bind parameters, direclty return return true; } if (parameters->_type != TRI_JSON_ARRAY) { // parameters must be a list TRI_SetErrorContextAql(context, TRI_ERROR_QUERY_BIND_PARAMETERS_INVALID, NULL); return false; } n = parameters->_value._objects._length; if (n == 0) { // empty list, this is ok return true; } for (i = 0; i < n; i += 2) { TRI_json_t* name = TRI_AtVector(¶meters->_value._objects, i); TRI_json_t* value = TRI_AtVector(¶meters->_value._objects, i + 1); TRI_aql_bind_parameter_t* parameter; assert(TRI_IsStringJson(name)); assert(value); parameter = CreateParameter(name->_value._string.data, name->_value._string.length - 1, value); if (parameter == NULL) { TRI_SetErrorContextAql(context, TRI_ERROR_OUT_OF_MEMORY, NULL); return false; } TRI_InsertKeyAssociativePointer(&context->_parameters._values, parameter->_name, parameter, false); } return true; }
static TRI_general_cursor_row_t GetAt (TRI_general_cursor_result_t const* result, const TRI_general_cursor_length_t n) { TRI_json_t* json = (TRI_json_t*) result->_data; TRI_ASSERT(json); return (TRI_general_cursor_row_t*) TRI_AtVector(&json->_value._objects, (size_t) n); }
static TRI_json_t* GetMergedKeyList (const TRI_json_t* const lhs, const TRI_json_t* const rhs) { TRI_json_t* keys; TRI_json_t* unique; size_t i, n; TRI_ASSERT(lhs->_type == TRI_JSON_ARRAY); TRI_ASSERT(rhs->_type == TRI_JSON_ARRAY); keys = TRI_CreateList2Json(TRI_UNKNOWN_MEM_ZONE, lhs->_value._objects._length + rhs->_value._objects._length); if (keys == NULL) { return NULL; } n = lhs->_value._objects._length; for (i = 0 ; i < n; i += 2) { TRI_json_t* key = TRI_AtVector(&lhs->_value._objects, i); TRI_ASSERT(TRI_IsStringJson(key)); TRI_PushBackListJson(TRI_UNKNOWN_MEM_ZONE, keys, key); } n = rhs->_value._objects._length; for (i = 0 ; i < n; i += 2) { TRI_json_t* key = TRI_AtVector(&rhs->_value._objects, i); TRI_ASSERT(TRI_IsStringJson(key)); TRI_PushBackListJson(TRI_UNKNOWN_MEM_ZONE, keys, key); } // sort the key list in place TRI_SortListJson(keys); // list is now sorted unique = TRI_UniquifyListJson(keys); TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, keys); return unique; // might be NULL }
static TRI_json_t* GetMergedKeyArray (TRI_json_t const* lhs, TRI_json_t const* rhs) { TRI_ASSERT(lhs->_type == TRI_JSON_OBJECT); TRI_ASSERT(rhs->_type == TRI_JSON_OBJECT); size_t n = TRI_LengthVector(&lhs->_value._objects) + TRI_LengthVector(&rhs->_value._objects); std::unique_ptr<TRI_json_t> keys(TRI_CreateArrayJson(TRI_UNKNOWN_MEM_ZONE, n)); if (keys == nullptr) { return nullptr; } if (TRI_CapacityVector(&(keys.get()->_value._objects)) < n) { return nullptr; } n = TRI_LengthVector(&lhs->_value._objects); for (size_t i = 0 ; i < n; i += 2) { auto key = static_cast<TRI_json_t const*>(TRI_AtVector(&lhs->_value._objects, i)); TRI_ASSERT(TRI_IsStringJson(key)); TRI_PushBackArrayJson(TRI_UNKNOWN_MEM_ZONE, keys.get(), key); } n = TRI_LengthVector(&rhs->_value._objects); for (size_t i = 0 ; i < n; i += 2) { auto key = static_cast<TRI_json_t const*>(TRI_AtVector(&rhs->_value._objects, i)); TRI_ASSERT(TRI_IsStringJson(key)); TRI_PushBackArrayJson(TRI_UNKNOWN_MEM_ZONE, keys.get(), key); } // sort the key array in place TRI_SortArrayJson(keys.get()); // array is now sorted return TRI_UniquifyArrayJson(keys.get()); }
bool TRI_DeleteArrayJson (TRI_memory_zone_t* zone, TRI_json_t* object, char const* name) { size_t n; size_t i; TRI_ASSERT(object->_type == TRI_JSON_ARRAY); TRI_ASSERT(name); n = object->_value._objects._length; for (i = 0; i < n; i += 2) { TRI_json_t* key; key = (TRI_json_t*) TRI_AtVector(&object->_value._objects, i); if (! IsString(key)) { continue; } if (TRI_EqualString(key->_value._string.data, name)) { TRI_json_t* old; // remove key old = (TRI_json_t*) TRI_AtVector(&object->_value._objects, i); if (old != NULL) { TRI_DestroyJson(zone, old); } TRI_RemoveVector(&object->_value._objects, i); // remove value old = (TRI_json_t*) TRI_AtVector(&object->_value._objects, i); if (old != NULL) { TRI_DestroyJson(zone, old); } TRI_RemoveVector(&object->_value._objects, i); return true; } } return false; }
TRI_json_t* TRI_LookupArrayJson (TRI_json_t const* array, size_t pos) { TRI_ASSERT(array->_type == TRI_JSON_ARRAY); size_t const n = TRI_LengthVector(&array->_value._objects); if (pos >= n) { // out of bounds return nullptr; } return static_cast<TRI_json_t*>(TRI_AtVector(&array->_value._objects, pos)); }
void BitarrayIndex_destroy(BitarrayIndex* baIndex) { size_t j; if (baIndex == NULL) { return; } for (j = 0; j < baIndex->_values._length; ++j) { TRI_DestroyJson(TRI_UNKNOWN_MEM_ZONE, (TRI_json_t*)(TRI_AtVector(&(baIndex->_values),j))); } TRI_DestroyVector(&baIndex->_values); TRI_FreeBitarray(baIndex->_bitarray); baIndex->_bitarray = NULL; }
bool TRI_ReplaceArrayJson (TRI_memory_zone_t* zone, TRI_json_t* object, char const* name, TRI_json_t* replacement) { size_t n; size_t i; TRI_ASSERT(object->_type == TRI_JSON_ARRAY); TRI_ASSERT(name); n = object->_value._objects._length; for (i = 0; i < n; i += 2) { TRI_json_t* key; key = (TRI_json_t*) TRI_AtVector(&object->_value._objects, i); if (! IsString(key)) { continue; } if (TRI_EqualString(key->_value._string.data, name)) { TRI_json_t copy; // retrieve the old element TRI_json_t* old = (TRI_json_t*) TRI_AtVector(&object->_value._objects, i + 1); if (old != NULL) { TRI_DestroyJson(zone, old); } TRI_CopyToJson(zone, ©, replacement); TRI_SetVector(&object->_value._objects, i + 1, ©); return true; } } // object not found in array, now simply add it TRI_Insert2ArrayJson(zone, object, name, replacement); return false; }
bool TRI_DeleteObjectJson (TRI_memory_zone_t* zone, TRI_json_t* object, char const* name) { TRI_ASSERT(object->_type == TRI_JSON_OBJECT); TRI_ASSERT(name != nullptr); size_t const n = TRI_LengthVector(&object->_value._objects); for (size_t i = 0; i < n; i += 2) { TRI_json_t* key = static_cast<TRI_json_t*>(TRI_AtVector(&object->_value._objects, i)); if (! IsString(key)) { continue; } if (TRI_EqualString(key->_value._string.data, name)) { // remove key TRI_json_t* old = static_cast<TRI_json_t*>(TRI_AtVector(&object->_value._objects, i)); if (old != nullptr) { TRI_DestroyJson(zone, old); } TRI_RemoveVector(&object->_value._objects, i); // remove value old = static_cast<TRI_json_t*>(TRI_AtVector(&object->_value._objects, i)); if (old != nullptr) { TRI_DestroyJson(zone, old); } TRI_RemoveVector(&object->_value._objects, i); return true; } } return false; }
TRI_json_t* TRI_LookupListJson (const TRI_json_t* const object, const size_t pos) { size_t n; assert(object->_type == TRI_JSON_LIST); n = object->_value._objects._length; if (pos >= n) { // out of bounds return NULL; } return TRI_AtVector(&object->_value._objects, pos); }
TRI_json_t* TRI_LookupListJson (TRI_json_t const* object, size_t pos) { size_t n; TRI_ASSERT(object->_type == TRI_JSON_LIST); n = object->_value._objects._length; if (pos >= n) { // out of bounds return NULL; } return (TRI_json_t*) TRI_AtVector(&object->_value._objects, pos); }
static void CompactifySimCollection (TRI_sim_collection_t* sim) { TRI_vector_t vector; size_t n; size_t i; if (! TRI_TRY_READ_LOCK_DATAFILES_SIM_COLLECTION(sim)) { return; } TRI_InitVector(&vector, TRI_UNKNOWN_MEM_ZONE, sizeof(TRI_doc_datafile_info_t)); // copy datafile information n = sim->base.base._datafiles._length; for (i = 0; i < n; ++i) { TRI_datafile_t* df; TRI_doc_datafile_info_t* dfi; df = sim->base.base._datafiles._buffer[i]; dfi = TRI_FindDatafileInfoDocCollection(&sim->base, df->_fid); TRI_PushBackVector(&vector, dfi); } TRI_READ_UNLOCK_DATAFILES_SIM_COLLECTION(sim); // handle datafiles with dead objects for (i = 0; i < vector._length; ++i) { TRI_doc_datafile_info_t* dfi; dfi = TRI_AtVector(&vector, i); if (dfi->_numberDead == 0) { continue; } LOG_DEBUG("datafile = %lu, alive = %lu / %lu, dead = %lu / %lu, deletions = %lu", (unsigned long) dfi->_fid, (unsigned long) dfi->_numberAlive, (unsigned long) dfi->_sizeAlive, (unsigned long) dfi->_numberDead, (unsigned long) dfi->_sizeDead, (unsigned long) dfi->_numberDeletion); CompactifyDatafile(sim, dfi->_fid); } // cleanup local variables TRI_DestroyVector(&vector); }
TRI_json_t* TRI_BetweenListJson (const TRI_json_t* const list, const TRI_json_t* const lower, const bool includeLower, const TRI_json_t* const upper, const bool includeUpper) { TRI_json_t* result; size_t i, n; TRI_ASSERT(list); TRI_ASSERT(list->_type == TRI_JSON_LIST); TRI_ASSERT(lower || upper); // create result list result = TRI_CreateListJson(TRI_UNKNOWN_MEM_ZONE); if (result == NULL) { return NULL; } n = list->_value._objects._length; for (i = 0; i < n; ++i) { TRI_json_t* p = TRI_AtVector(&list->_value._objects, i); if (lower) { // lower bound is set int compareResult = TRI_CompareValuesJson(lower, p); if (compareResult > 0 || (compareResult == 0 && ! includeLower)) { // element is bigger than lower bound continue; } } if (upper) { // upper bound is set int compareResult = TRI_CompareValuesJson(p, upper); if (compareResult > 0 || (compareResult == 0 && ! includeUpper)) { // element is smaller than upper bound continue; } } // element is between lower and upper bound TRI_PushBackListJson(TRI_UNKNOWN_MEM_ZONE, result, p); } return result; }
bool TRI_ReplaceObjectJson (TRI_memory_zone_t* zone, TRI_json_t* object, char const* name, TRI_json_t const* replacement) { TRI_ASSERT(object->_type == TRI_JSON_OBJECT); TRI_ASSERT(name != nullptr); size_t const n = TRI_LengthVector(&object->_value._objects); for (size_t i = 0; i < n; i += 2) { TRI_json_t* key = static_cast<TRI_json_t*>(TRI_AtVector(&object->_value._objects, i)); if (! IsString(key)) { continue; } if (TRI_EqualString(key->_value._string.data, name)) { // retrieve the old element TRI_json_t* old = static_cast<TRI_json_t*>(TRI_AtVector(&object->_value._objects, i + 1)); if (old != nullptr) { TRI_DestroyJson(zone, old); } TRI_json_t copy; TRI_CopyToJson(zone, ©, replacement); TRI_SetVector(&object->_value._objects, i + 1, ©); return true; } } // object not found in array, now simply add it TRI_Insert2ObjectJson(zone, object, name, replacement); return false; }
bool TRI_DeleteArrayJson (TRI_memory_zone_t* zone, TRI_json_t* array, size_t index) { TRI_ASSERT(TRI_IsArrayJson(array)); size_t const n = TRI_LengthArrayJson(array); if (index >= n) { return false; } TRI_json_t* element = static_cast<TRI_json_t*>(TRI_AtVector(&array->_value._objects, index)); TRI_ASSERT(element != nullptr); TRI_DestroyJson(zone, element); TRI_RemoveVector(&array->_value._objects, index); return true; }
static compaction_initial_context_t InitCompaction (TRI_document_collection_t* document, TRI_vector_t const* compactions) { compaction_initial_context_t context; size_t i, n; memset(&context, 0, sizeof(compaction_initial_context_t)); context._failed = false; context._document = document; // this is the minimum required size context._targetSize = sizeof(TRI_df_header_marker_t) + sizeof(TRI_col_header_marker_t) + sizeof(TRI_df_footer_marker_t) + 256; // allow for some overhead n = compactions->_length; for (i = 0; i < n; ++i) { TRI_datafile_t* df; compaction_info_t* compaction; bool ok; compaction = TRI_AtVector(compactions, i); df = compaction->_datafile; if (i == 0) { // extract and store fid context._fid = compaction->_datafile->_fid; } context._keepDeletions = compaction->_keepDeletions; ok = TRI_IterateDatafile(df, CalculateSize, &context, false, false); if (! ok) { context._failed = true; break; } } return context; }