in source/sigv4_quicksort.c [200:235]
static size_t partition( void * pArray,
size_t low,
size_t high,
size_t itemSize,
ComparisonFunc_t comparator )
{
uint8_t * pivot;
uint8_t * pArrayLocal = ( uint8_t * ) pArray;
size_t i = low - 1U, j = low;
assert( pArray != NULL );
assert( comparator != NULL );
/* Choose pivot as the highest indexed item in the current partition. */
pivot = &( pArrayLocal[ high * itemSize ] );
/* Iterate over all elements of the current array to partition it
* in comparison to the chosen pivot with smaller items on the left
* and larger or equal to items on the right. */
for( ; j < high; j++ )
{
/* Use comparator function to check current element is smaller than the pivot */
if( comparator( &( pArrayLocal[ j * itemSize ] ), pivot ) < 0 )
{
++i;
swap( &( pArrayLocal[ i * itemSize ] ), &( pArrayLocal[ j * itemSize ] ), itemSize );
}
}
/* Place the pivot between the smaller and larger item chunks of
* the array. This represents the 2 partitions of the array. */
swap( &( pArrayLocal[ ( i + 1U ) * itemSize ] ), pivot, itemSize );
/* Return the pivot item's index. */
return i + 1U;
}