|
|
|
@ -855,42 +855,36 @@ hb_in_ranges (T u, T lo1, T hi1, T lo2, T hi2, T lo3, T hi3) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T, typename T2> static inline void |
|
|
|
|
hb_bubble_sort (T *array, unsigned int len, int(*compar)(const T *, const T *), T2 *array2) |
|
|
|
|
hb_stable_sort (T *array, unsigned int len, int(*compar)(const T *, const T *), T2 *array2) |
|
|
|
|
{ |
|
|
|
|
if (unlikely (!len)) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
unsigned int k = len - 1; |
|
|
|
|
do { |
|
|
|
|
unsigned int new_k = 0; |
|
|
|
|
|
|
|
|
|
for (unsigned int j = 0; j < k; j++) |
|
|
|
|
if (compar (&array[j], &array[j+1]) > 0) |
|
|
|
|
for (unsigned int i = 1; i < len; i++) |
|
|
|
|
{ |
|
|
|
|
unsigned int j = i; |
|
|
|
|
while (j && compar (&array[j - 1], &array[i]) > 0) |
|
|
|
|
j--; |
|
|
|
|
if (i == j) |
|
|
|
|
continue; |
|
|
|
|
/* Move item i to occupy place for item j, shift what's in between. */ |
|
|
|
|
{ |
|
|
|
|
T t; |
|
|
|
|
t = array[j]; |
|
|
|
|
array[j] = array[j + 1]; |
|
|
|
|
array[j + 1] = t; |
|
|
|
|
t = array[i]; |
|
|
|
|
memmove (&array[j + 1], &array[j], (i - j) * sizeof (T)); |
|
|
|
|
array[j] = t; |
|
|
|
|
} |
|
|
|
|
if (array2) |
|
|
|
|
{ |
|
|
|
|
T2 t; |
|
|
|
|
t = array2[j]; |
|
|
|
|
array2[j] = array2[j + 1]; |
|
|
|
|
array2[j + 1] = t; |
|
|
|
|
t = array2[i]; |
|
|
|
|
memmove (&array2[j + 1], &array2[j], (i - j) * sizeof (T2)); |
|
|
|
|
array2[j] = t; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
new_k = j; |
|
|
|
|
} |
|
|
|
|
k = new_k; |
|
|
|
|
} while (k); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
template <typename T> static inline void |
|
|
|
|
hb_bubble_sort (T *array, unsigned int len, int(*compar)(const T *, const T *)) |
|
|
|
|
hb_stable_sort (T *array, unsigned int len, int(*compar)(const T *, const T *)) |
|
|
|
|
{ |
|
|
|
|
hb_bubble_sort (array, len, compar, (int *) NULL); |
|
|
|
|
hb_stable_sort (array, len, compar, (int *) NULL); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static inline hb_bool_t |
|
|
|
|