Scortch/sort.c
///	Bottom up merge sort that quadruples instead of doubles at each iteration
Bottom up merge sort that quadruples instead of doubles at each iteration
Bottom up merge sort that quadruples instead of doubles at each iteration
void bottomUpMergeFourSort(void *array, void *buffer, size_t count, size_t size, struct SortingStatistics *statistics, Compare compare, void *context) {
	if ( statistics ) {
		statistics->invocations += 1;
	}
	size_t block, index, limit, width = 4;
	void *p;
	for ( index = 0, p = array ; index + width <= count ; index += width, p += width * size ) {
		fourSort(p, size, buffer, statistics, compare, context);
	}
	switch ( count % 4 ) {
	case 2:
		if ( invokeIsLess(p + size, p, statistics, compare, context) ) {
			swapAt(p, 0, 1, size, buffer, statistics);
		}
		break;
	case 3:
		threeSort(p, size, buffer, statistics, compare, context);
		break;
	}
	while ( width < count ) {
		block = width * 4;
		for ( index = 0, p = array ; index + width < count ; index += block, p += block * size ) {
			limit = count - index < block ? count - index : block;
			mergeFourSorted(p, buffer, limit, width, size, statistics, compare, context);
		}
		width = block;
	}
}
void bottomUpMergeFourSort ( void * array , void * buffer , size_t count , size_t size , struct SortingStatistics * statistics , Compare compare , void * context ) { if ( statistics ) { statistics -> invocations += 1 ; } size_t block , index , limit , width = 4 ; void * p ; for ( index = 0 , p = array ; index + width <= count ; index += width , p += width * size ) { fourSort ( p , size , buffer , statistics , compare , context ) ; } switch ( count % 4 ) { case 2 : if ( invokeIsLess ( p + size , p , statistics , compare , context ) ) { swapAt ( p , 0 , 1 , size , buffer , statistics ) ; } break ; case 3 : threeSort ( p , size , buffer , statistics , compare , context ) ; break ; } while ( width < count ) { block = width * 4 ; for ( index = 0 , p = array ; index + width < count ; index += block , p += block * size ) { limit = count - index < block ? count - index : block ; mergeFourSorted ( p , buffer , limit , width , size , statistics , compare , context ) ; } width = block ; } }
Bottom up merge sort that quadruples instead of doubles at each iteration
Bottom up merge sort that quadruples instead of doubles at each iteration