diff --git a/arangod/HashIndex/hash-array.c b/arangod/HashIndex/hash-array.c index 0dae118c9e..b57dbe41f1 100644 --- a/arangod/HashIndex/hash-array.c +++ b/arangod/HashIndex/hash-array.c @@ -239,7 +239,7 @@ static void AddNewElement (TRI_hash_array_t* array, i = hash % array->_nrAlloc; while (! IsEmptyElement(array, &array->_table[i])) { - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); } // ........................................................................... @@ -441,7 +441,7 @@ TRI_hash_index_element_t* TRI_LookupByKeyHashArray (TRI_hash_array_t* array, while (! IsEmptyElement(array, &array->_table[i]) && ! IsEqualKeyElement(array, key, &array->_table[i])) { - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); } // ........................................................................... @@ -490,7 +490,7 @@ TRI_hash_index_element_t* TRI_LookupByElementHashArray (TRI_hash_array_t* array, while (! IsEmptyElement(array, &array->_table[i]) && ! IsEqualElementElement(array, element, &array->_table[i])) { - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); } // ........................................................................... @@ -545,7 +545,7 @@ int TRI_InsertElementHashArray (TRI_hash_array_t* array, while (! IsEmptyElement(array, &array->_table[i]) && ! IsEqualElementElement(array, element, &array->_table[i])) { - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); } arrayElement = &array->_table[i]; @@ -623,7 +623,7 @@ int TRI_InsertKeyHashArray (TRI_hash_array_t* array, while (! IsEmptyElement(array, &array->_table[i]) && ! IsEqualKeyElement(array, key, &array->_table[i])) { - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); } arrayElement = &array->_table[i]; @@ -696,7 +696,7 @@ int TRI_RemoveElementHashArray (TRI_hash_array_t* array, while (! IsEmptyElement(array, &array->_table[i]) && ! IsEqualElementElement(array, element, &array->_table[i])) { - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); } arrayElement = &array->_table[i]; @@ -723,7 +723,7 @@ int TRI_RemoveElementHashArray (TRI_hash_array_t* array, // so that there are no gaps in the array // ........................................................................... - k = (i + 1) % array->_nrAlloc; + k = TRI_IncModU64(i, array->_nrAlloc); while (! IsEmptyElement(array, &array->_table[k])) { uint64_t j = HashElement(array, &array->_table[k]) % array->_nrAlloc; @@ -734,7 +734,7 @@ int TRI_RemoveElementHashArray (TRI_hash_array_t* array, i = k; } - k = (k + 1) % array->_nrAlloc; + k = TRI_IncModU64(k, array->_nrAlloc); } return TRI_ERROR_NO_ERROR; @@ -765,7 +765,7 @@ int TRI_RemoveKeyHashArray (TRI_hash_array_t* array, while (! IsEmptyElement(array, &array->_table[i]) && ! IsEqualKeyElement(array, key, &array->_table[i])) { - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); } arrayElement = &array->_table[i]; @@ -791,7 +791,7 @@ int TRI_RemoveKeyHashArray (TRI_hash_array_t* array, // and now check the following places for items to move here // ........................................................................... - k = (i + 1) % array->_nrAlloc; + k = TRI_IncModU64(i, array->_nrAlloc); while (! IsEmptyElement(array, &array->_table[k])) { uint64_t j = HashElement(array, &array->_table[k]) % array->_nrAlloc; @@ -802,7 +802,7 @@ int TRI_RemoveKeyHashArray (TRI_hash_array_t* array, i = k; } - k = (k + 1) % array->_nrAlloc; + k = TRI_IncModU64(k, array->_nrAlloc); } // ........................................................................... @@ -861,7 +861,7 @@ TRI_vector_pointer_t TRI_LookupByKeyHashArrayMulti (TRI_hash_array_t* array, TRI_PushBackVectorPointer(&result, &array->_table[i]); } - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); } // ........................................................................... @@ -904,7 +904,7 @@ TRI_vector_pointer_t TRI_LookupByElementHashArrayMulti (TRI_hash_array_t* array, TRI_PushBackVectorPointer(&result, &array->_table[i]); } - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); } // ........................................................................... @@ -944,7 +944,7 @@ int TRI_InsertElementHashArrayMulti (TRI_hash_array_t* array, while (! IsEmptyElement(array, &array->_table[i]) && ! IsEqualElementElement(array, element, &array->_table[i])) { - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); } arrayElement = &array->_table[i]; @@ -1023,7 +1023,7 @@ int TRI_InsertKeyHashArrayMulti (TRI_hash_array_t* array, // ........................................................................... while (! IsEmptyElement(array, &array->_table[i])) { - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); } arrayElement = &array->_table[i]; @@ -1082,7 +1082,7 @@ int TRI_RemoveElementHashArrayMulti (TRI_hash_array_t* array, while (! IsEmptyElement(array, &array->_table[i]) && ! IsEqualElementElement(array, element, &array->_table[i])) { - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); } arrayElement = &array->_table[i]; @@ -1108,7 +1108,7 @@ int TRI_RemoveElementHashArrayMulti (TRI_hash_array_t* array, // and now check the following places for items to move here // ........................................................................... - k = (i + 1) % array->_nrAlloc; + k = TRI_IncModU64(i, array->_nrAlloc); while (! IsEmptyElement(array, &array->_table[k])) { uint64_t j = HashElement(array, &array->_table[k]) % array->_nrAlloc; @@ -1119,7 +1119,7 @@ int TRI_RemoveElementHashArrayMulti (TRI_hash_array_t* array, i = k; } - k = (k + 1) % array->_nrAlloc; + k = TRI_IncModU64(k, array->_nrAlloc); } return TRI_ERROR_NO_ERROR; @@ -1150,7 +1150,7 @@ int TRI_RemoveKeyHashArrayMulti (TRI_hash_array_t* array, while (! IsEmptyElement(array, &array->_table[i]) && ! IsEqualKeyElement(array, key, &array->_table[i])) { - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); } arrayElement = &array->_table[i]; @@ -1176,7 +1176,7 @@ int TRI_RemoveKeyHashArrayMulti (TRI_hash_array_t* array, // and now check the following places for items to move here // ........................................................................... - k = (i + 1) % array->_nrAlloc; + k = TRI_IncModU64(i, array->_nrAlloc); while (! IsEmptyElement(array, &array->_table[k])) { uint64_t j = HashElement(array, &array->_table[k]) % array->_nrAlloc; @@ -1187,7 +1187,7 @@ int TRI_RemoveKeyHashArrayMulti (TRI_hash_array_t* array, i = k; } - k = (k + 1) % array->_nrAlloc; + k = TRI_IncModU64(k, array->_nrAlloc); } return TRI_ERROR_NO_ERROR; diff --git a/arangod/VocBase/document-collection.c b/arangod/VocBase/document-collection.c index adb8270e95..e0665a8fb1 100644 --- a/arangod/VocBase/document-collection.c +++ b/arangod/VocBase/document-collection.c @@ -3741,6 +3741,7 @@ static int FillIndex (TRI_document_collection_t* document, void** end; void** ptr; int res; + double starttime; primary = &document->base; @@ -3754,6 +3755,9 @@ static int FillIndex (TRI_document_collection_t* document, } + starttime = TRI_microtime(); + printf("FillIndex _iid=%llu start time: %f\n",(unsigned long long) idx->_iid, + starttime); inserted = 0; for (; ptr < end; ++ptr) { @@ -3780,6 +3784,8 @@ static int FillIndex (TRI_document_collection_t* document, } } } + printf("FillIndex _iid=%llu time spent: %f\n",(unsigned long long) idx->_iid, + TRI_microtime()-starttime); return TRI_ERROR_NO_ERROR; } diff --git a/lib/Basics/AssociativeArray.h b/lib/Basics/AssociativeArray.h index 65fef8192b..5c735a5605 100644 --- a/lib/Basics/AssociativeArray.h +++ b/lib/Basics/AssociativeArray.h @@ -310,7 +310,7 @@ namespace triagens { uint64_t i = hash % _nrAlloc; while (!_desc.isEmptyElement(_table[i]) && !_desc.isEqualKeyElement(key, _table[i])) { - i = (i + 1) % _nrAlloc; + i = TRI_IncModU64(i, _nrAlloc); #ifdef TRI_INTERNAL_STATS _nrProbesF++; #endif @@ -337,7 +337,7 @@ namespace triagens { uint64_t i = hash % _nrAlloc; while (!_desc.isEmptyElement(_table[i]) && !_desc.isEqualElementElement(element, _table[i])) { - i = (i + 1) % _nrAlloc; + i = TRI_IncModU64(i, _nrAlloc); #ifdef TRI_INTERNAL_STATS _nrProbesF++; #endif @@ -363,7 +363,7 @@ namespace triagens { uint64_t i = hash % _nrAlloc; while (!_desc.isEmptyElement(_table[i]) && !_desc.isEqualElementElement(element, _table[i])) { - i = (i + 1) % _nrAlloc; + i = TRI_IncModU64(i, _nrAlloc); #ifdef TRI_INTERNAL_STATS _nrProbesA++; #endif @@ -431,7 +431,7 @@ namespace triagens { uint64_t i = hash % _nrAlloc; while (!_desc.isEmptyElement(_table[i]) && !_desc.isEqualKeyElement(key, _table[i])) { - i = (i + 1) % _nrAlloc; + i = TRI_IncModU64(i, _nrAlloc); #ifdef TRI_INTERNAL_STATS _nrProbesA++; #endif @@ -499,7 +499,7 @@ namespace triagens { uint64_t i = hash % _nrAlloc; while (!_desc.isEmptyElement(_table[i]) && !_desc.isEqualKeyElement(key, _table[i])) { - i = (i + 1) % _nrAlloc; + i = TRI_IncModU64(i, _nrAlloc); #ifdef TRI_INTERNAL_STATS _nrProbesD++; #endif @@ -518,7 +518,7 @@ namespace triagens { _nrUsed--; // and now check the following places for items to move here - uint64_t k = (i + 1) % _nrAlloc; + uint64_t k = TRI_IncModU64(i, _nrAlloc); while (!_desc.isEmptyElement(_table[k])) { uint32_t j = _desc.hashElement(_table[k]) % _nrAlloc; @@ -529,7 +529,7 @@ namespace triagens { i = k; } - k = (k + 1) % _nrAlloc; + k = TRI_IncModU64(k, _nrAlloc); } // return success @@ -552,7 +552,7 @@ namespace triagens { uint64_t i = hash % _nrAlloc; while (!_desc.isEmptyElement(_table[i]) && !_desc.isEqualElementElement(element, _table[i])) { - i = (i + 1) % _nrAlloc; + i = TRI_IncModU64(i, _nrAlloc); #ifdef TRI_INTERNAL_STATS _nrProbesD++; #endif @@ -568,7 +568,7 @@ namespace triagens { _nrUsed--; // and now check the following places for items to move here - uint64_t k = (i + 1) % _nrAlloc; + uint64_t k = TRI_IncModU64(i, _nrAlloc); while (!_desc.isEmptyElement(_table[k])) { uint32_t j = _desc.hashElement(_table[k]) % _nrAlloc; @@ -579,7 +579,7 @@ namespace triagens { i = k; } - k = (k + 1) % _nrAlloc; + k = TRI_IncModU64(k, _nrAlloc); } // return success @@ -639,7 +639,7 @@ namespace triagens { uint64_t i = hash % _nrAlloc; while (!_desc.isEmptyElement(_table[i])) { - i = (i + 1) % _nrAlloc; + i = TRI_IncModU64(i, _nrAlloc); #ifdef TRI_INTERNAL_STATS _nrProbesR++; #endif diff --git a/lib/BasicsC/associative-multi.c b/lib/BasicsC/associative-multi.c index 28576060ad..1c072ddeda 100644 --- a/lib/BasicsC/associative-multi.c +++ b/lib/BasicsC/associative-multi.c @@ -78,7 +78,7 @@ static void AddNewElement (TRI_multi_array_t* array, void* element) { i = hash % array->_nrAlloc; while (! array->isEmptyElement(array, array->_table + i * array->_elementSize)) { - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); #ifdef TRI_INTERNAL_STATS array->_nrProbesR++; #endif @@ -252,7 +252,7 @@ TRI_vector_pointer_t TRI_LookupByKeyMultiArray (TRI_memory_zone_t* zone, } #endif - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); } // ........................................................................... @@ -298,7 +298,7 @@ TRI_vector_pointer_t TRI_LookupByElementMultiArray (TRI_memory_zone_t* zone, } #endif - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); } // ........................................................................... @@ -336,7 +336,7 @@ bool TRI_InsertElementMultiArray (TRI_multi_array_t* array, void* element, bool // search the table while (! array->isEmptyElement(array, array->_table + i * array->_elementSize) && ! array->isEqualElementElement(array, element, array->_table + i * array->_elementSize)) { - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); #ifdef TRI_INTERNAL_STATS array->_nrProbesA++; #endif @@ -394,7 +394,7 @@ bool TRI_InsertKeyMultiArray (TRI_multi_array_t* array, void* key, void* element // search the table while (! array->isEmptyElement(array, array->_table + i * array->_elementSize)) { - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); #ifdef TRI_INTERNAL_STATS array->_nrProbesA++; #endif @@ -438,7 +438,7 @@ bool TRI_RemoveElementMultiArray (TRI_multi_array_t* array, void* element, void* // search the table while (! array->isEmptyElement(array, array->_table + i * array->_elementSize) && ! array->isEqualElementElement(array, element, array->_table + i * array->_elementSize)) { - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); #ifdef TRI_INTERNAL_STATS array->_nrProbesD++; #endif @@ -462,7 +462,7 @@ bool TRI_RemoveElementMultiArray (TRI_multi_array_t* array, void* element, void* array->_nrUsed--; // and now check the following places for items to move here - k = (i + 1) % array->_nrAlloc; + k = TRI_IncModU64(i, array->_nrAlloc); while (! array->isEmptyElement(array, array->_table + k * array->_elementSize)) { uint64_t j = array->hashElement(array, array->_table + k * array->_elementSize) % array->_nrAlloc; @@ -473,7 +473,7 @@ bool TRI_RemoveElementMultiArray (TRI_multi_array_t* array, void* element, void* i = k; } - k = (k + 1) % array->_nrAlloc; + k = TRI_IncModU64(k, array->_nrAlloc); } return true; @@ -500,7 +500,7 @@ bool TRI_RemoveKeyMultiArray (TRI_multi_array_t* array, void* key, void* old) { // search the table -- we can only match keys while (! array->isEmptyElement(array, array->_table + i * array->_elementSize) && ! array->isEqualKeyElement(array, key, array->_table + i * array->_elementSize)) { - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); #ifdef TRI_INTERNAL_STATS array->_nrProbesD++; #endif @@ -524,7 +524,7 @@ bool TRI_RemoveKeyMultiArray (TRI_multi_array_t* array, void* key, void* old) { array->_nrUsed--; // and now check the following places for items to move here - k = (i + 1) % array->_nrAlloc; + k = TRI_IncModU64(i, array->_nrAlloc); while (! array->isEmptyElement(array, array->_table + k * array->_elementSize)) { uint64_t j = array->hashElement(array, array->_table + k * array->_elementSize) % array->_nrAlloc; @@ -535,7 +535,7 @@ bool TRI_RemoveKeyMultiArray (TRI_multi_array_t* array, void* key, void* old) { i = k; } - k = (k + 1) % array->_nrAlloc; + k = TRI_IncModU64(k, array->_nrAlloc); } return true; @@ -573,7 +573,7 @@ static void AddNewElementPointer (TRI_multi_pointer_t* array, void* element) { i = hash % array->_nrAlloc; while (array->_table[i] != NULL) { - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); #ifdef TRI_INTERNAL_STATS array->_nrProbesR++; #endif @@ -744,7 +744,7 @@ TRI_vector_pointer_t TRI_LookupByKeyMultiPointer (TRI_memory_zone_t* zone, array->_nrProbesF++; } #endif - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); } // return whatever we found @@ -770,7 +770,7 @@ void* TRI_LookupByElementMultiPointer (TRI_multi_pointer_t* array, void const* e // search the table while (array->_table[i] != NULL && ! array->isEqualElementElement(array, element, array->_table[i])) { - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); #ifdef TRI_INTERNAL_STATS array->_nrProbesF++; #endif @@ -812,8 +812,10 @@ void* TRI_InsertElementMultiPointer (TRI_multi_pointer_t* array, // we use this flag to speed up initial insertion into the index, i.e. when the // index is built for a collection and we know for sure no duplicate elements // will be inserted - while (array->_table[i] != NULL && (! checkEquality || ! array->isEqualElementElement(array, element, array->_table[i]))) { - i = (i + 1) % array->_nrAlloc; + while (array->_table[i] != NULL && + (! checkEquality || + ! array->isEqualElementElement(array, element, array->_table[i]))) { + i = TRI_IncModU64(i, array->_nrAlloc); #ifdef TRI_INTERNAL_STATS array->_nrProbesA++; #endif @@ -862,7 +864,7 @@ void* TRI_RemoveElementMultiPointer (TRI_multi_pointer_t* array, void const* ele // search the table while (array->_table[i] != NULL && ! array->isEqualElementElement(array, element, array->_table[i])) { - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); #ifdef TRI_INTERNAL_STATS array->_nrProbesD++; #endif @@ -879,7 +881,7 @@ void* TRI_RemoveElementMultiPointer (TRI_multi_pointer_t* array, void const* ele array->_nrUsed--; // and now check the following places for items to move here - k = (i + 1) % array->_nrAlloc; + k = TRI_IncModU64(i, array->_nrAlloc); while (array->_table[k] != NULL) { uint64_t j = array->hashElement(array, array->_table[k]) % array->_nrAlloc; @@ -890,7 +892,7 @@ void* TRI_RemoveElementMultiPointer (TRI_multi_pointer_t* array, void const* ele i = k; } - k = (k + 1) % array->_nrAlloc; + k = TRI_IncModU64(k, array->_nrAlloc); } // return success diff --git a/lib/BasicsC/associative.c b/lib/BasicsC/associative.c index 60e7f1ef15..e1bbbabffc 100644 --- a/lib/BasicsC/associative.c +++ b/lib/BasicsC/associative.c @@ -78,7 +78,7 @@ static void AddNewElement (TRI_associative_array_t* array, void* element) { i = hash % array->_nrAlloc; while (! array->isEmptyElement(array, array->_table + i * array->_elementSize)) { - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); #ifdef TRI_INTERNAL_STATS array->_nrProbesR++; #endif @@ -244,7 +244,7 @@ void* TRI_LookupByKeyAssociativeArray (TRI_associative_array_t* array, void* key // search the table while (! array->isEmptyElement(array, array->_table + i * array->_elementSize) && ! array->isEqualKeyElement(array, key, array->_table + i * array->_elementSize)) { - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); #ifdef TRI_INTERNAL_STATS array->_nrProbesF++; #endif @@ -292,7 +292,7 @@ void* TRI_LookupByElementAssociativeArray (TRI_associative_array_t* array, void* // search the table while (! array->isEmptyElement(array, array->_table + i * array->_elementSize) && ! array->isEqualElementElement(array, element, array->_table + i * array->_elementSize)) { - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); #ifdef TRI_INTERNAL_STATS array->_nrProbesF++; #endif @@ -346,7 +346,7 @@ bool TRI_InsertElementAssociativeArray (TRI_associative_array_t* array, void* el // search the table while (! array->isEmptyElement(array, array->_table + i * array->_elementSize) && ! array->isEqualElementElement(array, element, array->_table + i * array->_elementSize)) { - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); #ifdef TRI_INTERNAL_STATS array->_nrProbesA++; #endif @@ -399,7 +399,7 @@ bool TRI_InsertKeyAssociativeArray (TRI_associative_array_t* array, void* key, v // search the table while (! array->isEmptyElement(array, array->_table + i * array->_elementSize) && ! array->isEqualKeyElement(array, key, array->_table + i * array->_elementSize)) { - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); #ifdef TRI_INTERNAL_STATS array->_nrProbesA++; #endif @@ -446,7 +446,7 @@ bool TRI_RemoveElementAssociativeArray (TRI_associative_array_t* array, void* el // search the table while (! array->isEmptyElement(array, array->_table + i * array->_elementSize) && ! array->isEqualElementElement(array, element, array->_table + i * array->_elementSize)) { - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); #ifdef TRI_INTERNAL_STATS array->_nrProbesD++; #endif @@ -470,7 +470,7 @@ bool TRI_RemoveElementAssociativeArray (TRI_associative_array_t* array, void* el array->_nrUsed--; // and now check the following places for items to move here - k = (i + 1) % array->_nrAlloc; + k = TRI_IncModU64(i, array->_nrAlloc); while (! array->isEmptyElement(array, array->_table + k * array->_elementSize)) { uint64_t j = array->hashElement(array, array->_table + k * array->_elementSize) % array->_nrAlloc; @@ -481,7 +481,7 @@ bool TRI_RemoveElementAssociativeArray (TRI_associative_array_t* array, void* el i = k; } - k = (k + 1) % array->_nrAlloc; + k = TRI_IncModU64(k, array->_nrAlloc); } // return success @@ -508,7 +508,7 @@ bool TRI_RemoveKeyAssociativeArray (TRI_associative_array_t* array, void* key, v // search the table while (! array->isEmptyElement(array, array->_table + i * array->_elementSize) && ! array->isEqualKeyElement(array, key, array->_table + i * array->_elementSize)) { - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); #ifdef TRI_INTERNAL_STATS array->_nrProbesD++; #endif @@ -532,7 +532,7 @@ bool TRI_RemoveKeyAssociativeArray (TRI_associative_array_t* array, void* key, v array->_nrUsed--; // and now check the following places for items to move here - k = (i + 1) % array->_nrAlloc; + k = TRI_IncModU64(i, array->_nrAlloc); while (! array->isEmptyElement(array, array->_table + k * array->_elementSize)) { uint64_t j = array->hashElement(array, array->_table + k * array->_elementSize) % array->_nrAlloc; @@ -543,7 +543,7 @@ bool TRI_RemoveKeyAssociativeArray (TRI_associative_array_t* array, void* key, v i = k; } - k = (k + 1) % array->_nrAlloc; + k = TRI_IncModU64(k, array->_nrAlloc); } // return success @@ -590,7 +590,7 @@ static void AddNewElementPointer (TRI_associative_pointer_t* array, void* elemen i = hash % array->_nrAlloc; while (array->_table[i] != NULL) { - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); #ifdef TRI_INTERNAL_STATS array->_nrProbesR++; #endif @@ -796,7 +796,7 @@ void* TRI_LookupByKeyAssociativePointer (TRI_associative_pointer_t* array, // search the table while (array->_table[i] != NULL && ! array->isEqualKeyElement(array, key, array->_table[i])) { - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); #ifdef TRI_INTERNAL_STATS array->_nrProbesF++; #endif @@ -826,7 +826,7 @@ void* TRI_LookupByElementAssociativePointer (TRI_associative_pointer_t* array, // search the table while (array->_table[i] != NULL && ! array->isEqualElementElement(array, element, array->_table[i])) { - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); #ifdef TRI_INTERNAL_STATS array->_nrProbesF++; #endif @@ -864,7 +864,7 @@ void* TRI_InsertElementAssociativePointer (TRI_associative_pointer_t* array, // search the table while (array->_table[i] != NULL && ! array->isEqualElementElement(array, element, array->_table[i])) { - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); #ifdef TRI_INTERNAL_STATS array->_nrProbesA++; #endif @@ -922,7 +922,7 @@ void* TRI_InsertKeyAssociativePointer (TRI_associative_pointer_t* array, // search the table while (array->_table[i] != NULL && ! array->isEqualKeyElement(array, key, array->_table[i])) { - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); #ifdef TRI_INTERNAL_STATS array->_nrProbesA++; #endif @@ -984,7 +984,7 @@ int TRI_InsertKeyAssociativePointer2 (TRI_associative_pointer_t* array, // search the table while (array->_table[i] != NULL && ! array->isEqualKeyElement(array, key, array->_table[i])) { - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); #ifdef TRI_INTERNAL_STATS array->_nrProbesA++; #endif @@ -1011,7 +1011,7 @@ int TRI_InsertKeyAssociativePointer2 (TRI_associative_pointer_t* array, i = hash % array->_nrAlloc; // search the table while (array->_table[i] != NULL && ! array->isEqualKeyElement(array, key, array->_table[i])) { - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); #ifdef TRI_INTERNAL_STATS array->_nrProbesA++; #endif @@ -1046,7 +1046,7 @@ void* TRI_RemoveElementAssociativePointer (TRI_associative_pointer_t* array, // search the table while (array->_table[i] != NULL && ! array->isEqualElementElement(array, element, array->_table[i])) { - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); #ifdef TRI_INTERNAL_STATS array->_nrProbesD++; #endif @@ -1063,7 +1063,7 @@ void* TRI_RemoveElementAssociativePointer (TRI_associative_pointer_t* array, array->_nrUsed--; // and now check the following places for items to move here - k = (i + 1) % array->_nrAlloc; + k = TRI_IncModU64(i, array->_nrAlloc); while (array->_table[k] != NULL) { uint64_t j = array->hashElement(array, array->_table[k]) % array->_nrAlloc; @@ -1074,7 +1074,7 @@ void* TRI_RemoveElementAssociativePointer (TRI_associative_pointer_t* array, i = k; } - k = (k + 1) % array->_nrAlloc; + k = TRI_IncModU64(k, array->_nrAlloc); } // return success @@ -1102,7 +1102,7 @@ void* TRI_RemoveKeyAssociativePointer (TRI_associative_pointer_t* array, // search the table while (array->_table[i] != NULL && ! array->isEqualKeyElement(array, key, array->_table[i])) { - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); #ifdef TRI_INTERNAL_STATS array->_nrProbesD++; #endif @@ -1119,7 +1119,7 @@ void* TRI_RemoveKeyAssociativePointer (TRI_associative_pointer_t* array, array->_nrUsed--; // and now check the following places for items to move here - k = (i + 1) % array->_nrAlloc; + k = TRI_IncModU64(i, array->_nrAlloc); while (array->_table[k] != NULL) { uint64_t j = array->hashElement(array, array->_table[k]) % array->_nrAlloc; @@ -1130,7 +1130,7 @@ void* TRI_RemoveKeyAssociativePointer (TRI_associative_pointer_t* array, i = k; } - k = (k + 1) % array->_nrAlloc; + k = TRI_IncModU64(k, array->_nrAlloc); } // return success @@ -1179,7 +1179,7 @@ static void AddNewElementSynced (TRI_associative_synced_t* array, void* element) i = hash % array->_nrAlloc; while (array->_table[i] != NULL) { - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); #ifdef TRI_INTERNAL_STATS array->_nrProbesR++; #endif @@ -1343,7 +1343,7 @@ void const* TRI_LookupByKeyAssociativeSynced (TRI_associative_synced_t* array, TRI_ReadLockReadWriteLock(&array->_lock); while (array->_table[i] != NULL && ! array->isEqualKeyElement(array, key, array->_table[i])) { - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); #ifdef TRI_INTERNAL_STATS array->_nrProbesF++; #endif @@ -1380,7 +1380,7 @@ void const* TRI_LookupByElementAssociativeSynced (TRI_associative_synced_t* arra TRI_ReadLockReadWriteLock(&array->_lock); while (array->_table[i] != NULL && ! array->isEqualElementElement(array, element, array->_table[i])) { - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); #ifdef TRI_INTERNAL_STATS array->_nrProbesF++; #endif @@ -1423,7 +1423,7 @@ void* TRI_InsertElementAssociativeSynced (TRI_associative_synced_t* array, TRI_WriteLockReadWriteLock(&array->_lock); while (array->_table[i] != NULL && ! array->isEqualElementElement(array, element, array->_table[i])) { - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); #ifdef TRI_INTERNAL_STATS array->_nrProbesA++; #endif @@ -1480,7 +1480,7 @@ void* TRI_InsertKeyAssociativeSynced (TRI_associative_synced_t* array, TRI_WriteLockReadWriteLock(&array->_lock); while (array->_table[i] != NULL && ! array->isEqualKeyElement(array, key, array->_table[i])) { - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); #ifdef TRI_INTERNAL_STATS array->_nrProbesA++; #endif @@ -1530,7 +1530,7 @@ void* TRI_RemoveElementAssociativeSynced (TRI_associative_synced_t* array, TRI_WriteLockReadWriteLock(&array->_lock); while (array->_table[i] != NULL && ! array->isEqualElementElement(array, element, array->_table[i])) { - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); #ifdef TRI_INTERNAL_STATS array->_nrProbesD++; #endif @@ -1548,7 +1548,7 @@ void* TRI_RemoveElementAssociativeSynced (TRI_associative_synced_t* array, array->_nrUsed--; // and now check the following places for items to move here - k = (i + 1) % array->_nrAlloc; + k = TRI_IncModU64(i, array->_nrAlloc); while (array->_table[k] != NULL) { uint64_t j = array->hashElement(array, array->_table[k]) % array->_nrAlloc; @@ -1559,7 +1559,7 @@ void* TRI_RemoveElementAssociativeSynced (TRI_associative_synced_t* array, i = k; } - k = (k + 1) % array->_nrAlloc; + k = TRI_IncModU64(k, array->_nrAlloc); } // return success @@ -1590,7 +1590,7 @@ void* TRI_RemoveKeyAssociativeSynced (TRI_associative_synced_t* array, TRI_WriteLockReadWriteLock(&array->_lock); while (array->_table[i] != NULL && ! array->isEqualKeyElement(array, key, array->_table[i])) { - i = (i + 1) % array->_nrAlloc; + i = TRI_IncModU64(i, array->_nrAlloc); #ifdef TRI_INTERNAL_STATS array->_nrProbesD++; #endif @@ -1608,7 +1608,7 @@ void* TRI_RemoveKeyAssociativeSynced (TRI_associative_synced_t* array, array->_nrUsed--; // and now check the following places for items to move here - k = (i + 1) % array->_nrAlloc; + k = TRI_IncModU64(i, array->_nrAlloc); while (array->_table[k] != NULL) { uint64_t j = array->hashElement(array, array->_table[k]) % array->_nrAlloc; @@ -1619,7 +1619,7 @@ void* TRI_RemoveKeyAssociativeSynced (TRI_associative_synced_t* array, i = k; } - k = (k + 1) % array->_nrAlloc; + k = TRI_IncModU64(k, array->_nrAlloc); } // return success diff --git a/lib/BasicsC/common.h b/lib/BasicsC/common.h index e167f67dff..a70bdcb113 100644 --- a/lib/BasicsC/common.h +++ b/lib/BasicsC/common.h @@ -191,6 +191,19 @@ static inline void* CONST_CAST (void const* ptr) { return cnv.p; } +//////////////////////////////////////////////////////////////////////////////// +/// @brief incrementing a uint64_t modulo a number with wraparound +//////////////////////////////////////////////////////////////////////////////// + +static inline uint64_t TRI_IncModU64(uint64_t i, uint64_t len) { + // Note that the dummy variable gives the compiler a (good) chance to + // use a conditional move instruction instead of a branch. This actually + // works on modern gcc. + uint64_t dummy; + dummy = (++i) - len; + return i < len ? i : dummy; +} + //////////////////////////////////////////////////////////////////////////////// /// @brief a wrapper for assert() ///