Bio/Cluster/mysort.h
/* Insertion sort is best when the array is small*/
Insertion sort is best when the array is small
Insertion sort is best when the array is small
inline void
insertion_sort(double a[], int l, int r)
{
	if (r <= l) return;
	int i, j;
	double value;
	i = l; j = r;
	value = a[(l + r) >> 1];
	while (i <= j) {
		while (a[i] < value) i++;
		while (a[j] > value) j--;
		if (i <= j) {
			swap_f64(a[i], a[j]);
			i++;
			j--;
		}
	}
	for (i = l + 1; i <= r; i++) {
		j = i - 1;
		value = a[i];
		while (j >= l && a[j] > value) {
			a[j + 1] = a[j];
			j--;
		}
		a[j + 1] = value;
	}
}
inline void insertion_sort ( double a [ ] , int l , int r ) { if ( r <= l ) return ; int i , j ; double value ; i = l ; j = r ; value = a [ ( l + r ) >> 1 ] ; while ( i <= j ) { while ( a [ i ] < value ) i ++ ; while ( a [ j ] > value ) j -- ; if ( i <= j ) { swap_f64 ( a [ i ] , a [ j ] ) ; i ++ ; j -- ; } } for ( i = l + 1 ; i <= r ; i ++ ) { j = i - 1 ; value = a [ i ] ; while ( j >= l && a [ j ] > value ) { a [ j + 1 ] = a [ j ] ; j -- ; } a [ j + 1 ] = value ; } }
Insertion sort is best when the array is small
Insertion sort is best when the array is small
/* Performing 1 quicksort loops increase performance by 20-30% on random data,
	 * and completely eliminate worst-case scenario. It's slower when the array is
	 * sorted, but in that case the sort time is already tiny.
	 */