MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / calculateRunSize

Function calculateRunSize

sort/timsort.go:22–33  ·  view source on GitHub ↗

calculateRunSize returns a run size parameter that is further used to slice the data slice.

(dataLength int)

Source from the content-addressed store, hash-verified

20// calculateRunSize returns a run size parameter that is further used
21// to slice the data slice.
22func 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.
36func insertionSortRuns[T constraints.Ordered](data []T, runSize int) {

Callers 1

TimsortFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected