Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.jl.cov
*.jl.*.cov
*.jl.mem
Manifest.toml
11 changes: 6 additions & 5 deletions src/group.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ function group(groups, values)

out = Dictionary{I, Vector{T}}()
@inbounds for (group, value) in zip(groups, values)
push!(get!(Vector{T}, out, group), value)
tmp = get!(() -> T[value], out, group)
last(tmp) == value || push!(tmp, value)
end

return out
Expand Down Expand Up @@ -295,8 +296,8 @@ function groupfind(container)

out = Dictionary{I, Vector{T}}()
@inbounds for i in keys(container)
tmp = get!(Vector{T}, out, container[i])
push!(tmp, i)
tmp = get!(() -> T[i], out, container[i])
last(tmp) == i || push!(tmp, i)
end
return out
end
Expand All @@ -307,8 +308,8 @@ function groupfind(inds::AbstractIndices)

out = Dictionary{I, Vector{T}}()
for i in inds
tmp = get!(Vector{T}, out, i)
push!(tmp, i)
tmp = get!(() -> T[i], out, container[i])
last(tmp) == i || push!(tmp, i)
end
return out
end
Expand Down
2 changes: 2 additions & 0 deletions test/group.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
@test group(iseven, x -> x*2, 1:10)::Dictionary == dictionary([false => [2,6,10,14,18], true => [4,8,12,16,20]])

@test group((x,y) -> iseven(x+y), (x,y) -> x, 1:10, [1,3,4,2,5,6,4,2,3,9])::Dictionary == dictionary([true => [1,4,5,6,8,9], false => [2,3,7,10]])

@test group(isnothing, [1, 2, 3, nothing, 4, 5, nothing])::Dictionary == dictionary([false => [1, 2, 3, 4, 5], true => [nothing, nothing]])
end

@testset "grouponly" begin
Expand Down