in source/sigv4_quicksort.c [63:123]
static void swap( void * pFirstItem,
void * pSecondItem,
size_t itemSize );
/**
* @brief A helper function to perform quicksort on a subarray.
*
* @param[in] pArray The array to be sorted.
* @param[in] low The low index of the array.
* @param[in] high The high index of the array.
* @param[in] itemSize The amount of memory per entry in the array.
* @param[out] comparator The comparison function to determine if one item is less than another.
*/
static void quickSortHelper( void * pArray,
size_t low,
size_t high,
size_t itemSize,
ComparisonFunc_t comparator );
/**
* @brief A helper function to partition a subarray using the last element
* of the array as the pivot. All items smaller than the pivot end up
* at its left while all items greater than end up at its right.
*
* @param[in] pArray The array to be sorted.
* @param[in] low The low index of the array.
* @param[in] high The high index of the array.
* @param[in] itemSize The amount of memory per entry in the array.
* @param[out] comparator The comparison function to determine if one item is less than another.
*
* @return The index of the pivot
*/
static size_t partition( void * pArray,
size_t low,
size_t high,
size_t itemSize,
ComparisonFunc_t comparator );
/*-----------------------------------------------------------*/
static void swap( void * pFirstItem,
void * pSecondItem,
size_t itemSize )
{
uint8_t * pFirstByte = pFirstItem;
uint8_t * pSecondByte = pSecondItem;
size_t dataSize = itemSize;
assert( pFirstItem != NULL );
assert( pSecondItem != NULL );
/* Swap one byte at a time. */
while( dataSize-- > 0U )
{
uint8_t tmp = *pFirstByte;
*pFirstByte = *pSecondByte;
++pFirstByte;
*pSecondByte = tmp;
++pSecondByte;
}
}