Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store first value in Dict directly in innerjoin #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
15 changes: 13 additions & 2 deletions src/innerjoin.jl
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,20 @@ function _innerjoin!(out, l::AbstractArray, r::AbstractArray, v::AbstractArray,
else
lkeys = keys(l)
V = eltype(lkeys)
dict = Dict{eltype(l), Vector{V}}()
# For bitstypes i_l::V we can avoid allocating a vector by storing
# i_l directly in the Dict until a second matching i_l comes along
dict = Dict{eltype(l), Union{V,Vector{V}}}()
@inbounds for i_l ∈ lkeys
push!(get!(Vector{V}, dict, l[i_l]), i_l)
dict_index = Base.ht_keyindex2!(dict, l[i_l])
if dict_index > 0
old = dict.vals[dict_index]
new = old isa V ? [old, i_l] : push!(old, new)
dict.age += 1
dict.keys[dict_index] = l[i_l]
dict.vals[dict_index] = new
else
Base._setindex!(dict, i_l, l[i_l], -dict_index)
end
end

@inbounds for i_r in keys(r)
Expand Down