static void DestroyElement (TRI_hash_array_t* array, TRI_hash_index_element_t* element) { if (element != NULL) { if (element->_document != NULL) { TRI_Free(TRI_UNKNOWN_MEM_ZONE, element->_subObjects); } } ClearElement(array, element); }
int TRI_RemoveKeyHashArray (TRI_hash_array_t* array, TRI_index_search_value_t* key) { uint64_t hash; uint64_t i; uint64_t k; bool found; void* arrayElement; // ........................................................................... // compute the hash // ........................................................................... hash = HashKey(array, key); i = hash % array->_nrAlloc; // ........................................................................... // update statistics // ........................................................................... #ifdef TRI_INTERNAL_STATS array->_nrRems++; #endif // ........................................................................... // search the table // ........................................................................... while (! IsEmptyElement(array, &array->_table[i]) && ! IsEqualKeyElement(array, key, &array->_table[i])) { i = (i + 1) % array->_nrAlloc; #ifdef TRI_INTERNAL_STATS array->_nrProbesD++; #endif } arrayElement = &array->_table[i]; // ........................................................................... // if we did not find such an item return false // ........................................................................... found = ! IsEmptyElement(array, arrayElement); if (! found) { return TRI_RESULT_KEY_NOT_FOUND; } // ........................................................................... // remove item // ........................................................................... DestroyElement(array, arrayElement); array->_nrUsed--; // ........................................................................... // and now check the following places for items to move here // ........................................................................... k = (i + 1) % array->_nrAlloc; while (! IsEmptyElement(array, &array->_table[k])) { uint64_t j = HashElement(array, &array->_table[k]) % array->_nrAlloc; if ((i < k && !(i < j && j <= k)) || (k < i && !(i < j || j <= k))) { array->_table[i] = array->_table[k]; ClearElement(array, &array->_table[k]); i = k; } k = (k + 1) % array->_nrAlloc; } // ........................................................................... // return success // ........................................................................... return TRI_ERROR_NO_ERROR; }
int TRI_RemoveElementHashArray (TRI_hash_array_t* array, TRI_hash_index_element_t* element) { uint64_t hash; uint64_t i; uint64_t k; bool found; void* arrayElement; // ........................................................................... // compute the hash // ........................................................................... hash = HashElement(array, element); i = hash % array->_nrAlloc; // ........................................................................... // update statistics // ........................................................................... #ifdef TRI_INTERNAL_STATS array->_nrRems++; #endif // ........................................................................... // search the table // ........................................................................... while (! IsEmptyElement(array, &array->_table[i]) && ! IsEqualElementElement(array, element, &array->_table[i])) { i = (i + 1) % array->_nrAlloc; #ifdef TRI_INTERNAL_STATS array->_nrProbesD++; #endif } arrayElement = &array->_table[i]; // ........................................................................... // if we did not find such an item return false // ........................................................................... found = ! IsEmptyElement(array, arrayElement); if (! found) { return TRI_RESULT_ELEMENT_NOT_FOUND; } // ........................................................................... // remove item - destroy any internal memory associated with the element structure // ........................................................................... DestroyElement(array, arrayElement); array->_nrUsed--; // ........................................................................... // and now check the following places for items to move closer together // so that there are no gaps in the array // ........................................................................... k = (i + 1) % array->_nrAlloc; while (! IsEmptyElement(array, &array->_table[k])) { uint64_t j = HashElement(array, &array->_table[k]) % array->_nrAlloc; if ((i < k && !(i < j && j <= k)) || (k < i && !(i < j || j <= k))) { array->_table[i] = array->_table[k]; ClearElement(array, &array->_table[k]); i = k; } k = (k + 1) % array->_nrAlloc; } return TRI_ERROR_NO_ERROR; }
init_oia() { ClearElement(OperatorInformationArea); }