(data []T)
| 12 | import "github.com/TheAlgorithms/Go/constraints" |
| 13 | |
| 14 | func Count[T constraints.Integer](data []T) []T { |
| 15 | if len(data) == 0 { |
| 16 | return data |
| 17 | } |
| 18 | var aMin, aMax = data[0], data[0] |
| 19 | for _, x := range data { |
| 20 | if x < aMin { |
| 21 | aMin = x |
| 22 | } |
| 23 | if x > aMax { |
| 24 | aMax = x |
| 25 | } |
| 26 | } |
| 27 | count := make([]int, aMax-aMin+1) |
| 28 | for _, x := range data { |
| 29 | count[x-aMin]++ // this is the reason for having only Integer constraint instead of Ordered. |
| 30 | } |
| 31 | z := 0 |
| 32 | for i, c := range count { |
| 33 | for c > 0 { |
| 34 | data[z] = T(i) + aMin |
| 35 | z++ |
| 36 | c-- |
| 37 | } |
| 38 | } |
| 39 | return data |
| 40 | } |
nothing calls this directly
no outgoing calls
no test coverage detected