Scortch/sort.c
///	Insertion sort that uses a binary search to place each element
Insertion sort that uses a binary search to place each element
Insertion sort that uses a binary search to place each element
void binaryInsertionSort(void *array, size_t count, size_t size, size_t sorted, void *temporary, struct SortingStatistics *statistics, Compare compare, void *context) {
	if ( statistics ) {
		statistics->invocations += 1;
	}
	size_t i, m, n, o;
	for ( i = sorted ; i < count ; ++i ) {
		m = 1;
		n = i;
		while ( m <= n ) {
			o = (m + n) / 2 - 1;
			if ( invokeIsLess(array + i * size, array + o * size, statistics, compare, context) ) {
				n = o;
			} else {
				m = o + 2;
			}
		}
		if ( m <= i ) {
			slideDown(array, i, m - 1, size, temporary, statistics);
		}
	}
}
void binaryInsertionSort ( void * array , size_t count , size_t size , size_t sorted , void * temporary , struct SortingStatistics * statistics , Compare compare , void * context ) { if ( statistics ) { statistics -> invocations += 1 ; } size_t i , m , n , o ; for ( i = sorted ; i < count ; ++ i ) { m = 1 ; n = i ; while ( m <= n ) { o = ( m + n ) / 2 - 1 ; if ( invokeIsLess ( array + i * size , array + o * size , statistics , compare , context ) ) { n = o ; } else { m = o + 2 ; } } if ( m <= i ) { slideDown ( array , i , m - 1 , size , temporary , statistics ) ; } } }
Insertion sort that uses a binary search to place each element
Insertion sort that uses a binary search to place each element