Scortch/sort.c
/// Merge sort that uses insertion sort when the pieces are small instead of descending to single element arrays
Merge sort that uses insertion sort when the pieces are small instead of descending to single element arrays
Merge sort that uses insertion sort when the pieces are small instead of descending to single element arrays
void insertionMergeSort(void *array, size_t count, size_t size, void *buffer, size_t space, struct SortingStatistics *statistics, Compare compare, void *context) {
	if ( count < 2 ) {
		return;
	} else if ( count < 32 ) {
		binaryInsertionSort(array, count, size, 1, buffer, statistics, compare, context);
	} else {
		size_t half = count / 2;
		insertionMergeSort(array, half, size, buffer, space, statistics, compare, context);
		insertionMergeSort(array + half * size, count - half, size, buffer, space, statistics, compare, context);
		mergeSorted(array, count, half, size, buffer, space, statistics, compare, context);
	}
}
void insertionMergeSort ( void * array , size_t count , size_t size , void * buffer , size_t space , struct SortingStatistics * statistics , Compare compare , void * context ) { if ( count < 2 ) { return ; } else if ( count < 32 ) { binaryInsertionSort ( array , count , size , 1 , buffer , statistics , compare , context ) ; } else { size_t half = count / 2 ; insertionMergeSort ( array , half , size , buffer , space , statistics , compare , context ) ; insertionMergeSort ( array + half * size , count - half , size , buffer , space , statistics , compare , context ) ; mergeSorted ( array , count , half , size , buffer , space , statistics , compare , context ) ; } }
Merge sort that uses insertion sort when the pieces are small instead of descending to single element arrays
Merge sort that uses insertion sort when the pieces are small instead of descending to single element arrays