1
0
Fork 0

Cleanup resizing of MultiPointerHash

This commit is contained in:
Max Neunhoeffer 2014-03-28 09:14:20 +01:00
parent 3dc507d0ed
commit 05c9e4fd54
2 changed files with 24 additions and 10 deletions

View File

@ -925,8 +925,8 @@ static int SizeHintEdge (TRI_index_t* idx,
// 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 and allow for some new nodes to be created
// without resizing
// 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);
}

View File

@ -43,6 +43,12 @@
#define INITIAL_SIZE (64)
////////////////////////////////////////////////////////////////////////////////
/// @brief forward declaration
////////////////////////////////////////////////////////////////////////////////
static int ResizeMultiPointer (TRI_multi_pointer_t* array, size_t size);
// -----------------------------------------------------------------------------
// --SECTION-- constructors and destructors
// -----------------------------------------------------------------------------
@ -366,7 +372,7 @@ void* TRI_InsertElementMultiPointer (TRI_multi_pointer_t* array,
// if we were adding and the table is more than half full, extend it
if (array->_nrAlloc < 2 * array->_nrUsed) {
TRI_ResizeMultiPointer(array, 2 * array->_nrAlloc + 1);
ResizeMultiPointer(array, 2 * array->_nrAlloc + 1);
}
return NULL;
@ -486,22 +492,18 @@ void* TRI_RemoveElementMultiPointer (TRI_multi_pointer_t* array, void const* ele
}
////////////////////////////////////////////////////////////////////////////////
/// @brief resize the array
/// @brief resize the array, internal version taking the size as given
////////////////////////////////////////////////////////////////////////////////
int TRI_ResizeMultiPointer (TRI_multi_pointer_t* array, size_t size) {
static int ResizeMultiPointer (TRI_multi_pointer_t* array, size_t size) {
TRI_multi_pointer_entry_t* oldTable;
uint64_t oldAlloc;
uint64_t j;
if (size < 2*array->_nrUsed) {
return TRI_ERROR_BAD_PARAMETER;
}
oldTable = array->_table;
oldAlloc = array->_nrAlloc;
array->_nrAlloc = TRI_NextPrime((uint64_t) size*2);
array->_nrAlloc = TRI_NextPrime((uint64_t) size);
array->_table = TRI_Allocate(array->_memoryZone,
array->_nrAlloc * sizeof(TRI_multi_pointer_t), true);
@ -529,6 +531,18 @@ int TRI_ResizeMultiPointer (TRI_multi_pointer_t* array, size_t size) {
return TRI_ERROR_NO_ERROR;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief resize the array, adds a reserve of a factor of 2
////////////////////////////////////////////////////////////////////////////////
int TRI_ResizeMultiPointer (TRI_multi_pointer_t* array, size_t size) {
if (2*size+1 < array->_nrUsed) {
return TRI_ERROR_BAD_PARAMETER;
}
return ResizeMultiPointer(array, 2*size+1);
}
// Local Variables:
// mode: outline-minor
// outline-regexp: "/// @brief\\|/// {@inheritDoc}\\|/// @addtogroup\\|/// @page\\|// --SECTION--\\|/// @\\}"