calculateRunSize returns a run size parameter that is further used to slice the data slice.
(dataLength int)
| 20 | // calculateRunSize returns a run size parameter that is further used |
| 21 | // to slice the data slice. |
| 22 | func calculateRunSize(dataLength int) int { |
| 23 | remainder := 0 |
| 24 | for dataLength >= runSizeThreshold { |
| 25 | if dataLength%2 == 1 { |
| 26 | remainder = 1 |
| 27 | } |
| 28 | |
| 29 | dataLength = dataLength / 2 |
| 30 | } |
| 31 | |
| 32 | return dataLength + remainder |
| 33 | } |
| 34 | |
| 35 | // insertionSortRuns runs insertion sort on all the data runs one by one. |
| 36 | func insertionSortRuns[T constraints.Ordered](data []T, runSize int) { |