We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 1abd62e commit 620436cCopy full SHA for 620436c
1 file changed
src/result.jl
@@ -64,9 +64,16 @@ Assumes the colors are contiguously numbered from `1` to some `cmax`.
64
function group_by_color(color::AbstractVector{<:Integer})
65
cmin, cmax = extrema(color)
66
@assert cmin == 1
67
- group = [Int[] for c in 1:cmax]
+ group_sizes = zeros(Int, cmax)
68
+ for c in color
69
+ group_sizes[c] += 1
70
+ end
71
+ group = [Vector{Int}(undef, group_sizes[c]) for c in 1:cmax]
72
+ fill!(group_sizes, 1)
73
for (k, c) in enumerate(color)
- push!(group[c], k)
74
+ pos = group_sizes[c]
75
+ group[c][pos] = k
76
77
end
78
return group
79
0 commit comments