| 40 | */ |
| 41 | |
| 42 | static inline void |
| 43 | store_pivot(npy_intp pivot, npy_intp kth, npy_intp *pivots, npy_intp *npiv) |
| 44 | { |
| 45 | if (pivots == NULL) { |
| 46 | return; |
| 47 | } |
| 48 | |
| 49 | /* |
| 50 | * If pivot is the requested kth store it, overwriting other pivots if |
| 51 | * required. This must be done so iterative partition can work without |
| 52 | * manually shifting lower data offset by kth each time |
| 53 | */ |
| 54 | if (pivot == kth && *npiv == NPY_MAX_PIVOT_STACK) { |
| 55 | pivots[*npiv - 1] = pivot; |
| 56 | } |
| 57 | /* |
| 58 | * we only need pivots larger than current kth, larger pivots are not |
| 59 | * useful as partitions on smaller kth would reorder the stored pivots |
| 60 | */ |
| 61 | else if (pivot >= kth && *npiv < NPY_MAX_PIVOT_STACK) { |
| 62 | pivots[*npiv] = pivot; |
| 63 | (*npiv) += 1; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | template <typename type, bool arg> |
| 68 | struct Sortee { |