From 95c56c8e006bf7dfbdd59b31641720bb68da7038 Mon Sep 17 00:00:00 2001 From: Andy Ferris Date: Tue, 4 Aug 2020 10:20:23 +1000 Subject: [PATCH] Fix type instabilities in `_innerjoin!` Innerjoin is 3x faster on simple test case --- Project.toml | 2 +- src/innerjoin.jl | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Project.toml b/Project.toml index d08efb4..4400960 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ authors = ["Andy Ferris "] name = "SplitApplyCombine" uuid = "03a91e81-4c3e-53e1-a0a4-9c0c8f19dd66" -version = "1.1.1" +version = "1.1.2" [deps] Indexing = "313cdc1a-70c2-5d6a-ae34-0150d3930a38" diff --git a/src/innerjoin.jl b/src/innerjoin.jl index 25d8cc4..4cb94a7 100644 --- a/src/innerjoin.jl +++ b/src/innerjoin.jl @@ -109,7 +109,7 @@ function _innerjoin!(out, l::AbstractArray, r::AbstractArray, v::AbstractArray, V = eltype(rkeys) dict = Dict{eltype(r), Vector{V}}() @inbounds for i_r ∈ rkeys - push!(get!(()->Vector{V}(), dict, r[i_r]), i_r) + push!(get!(Vector{V}, dict, r[i_r]), i_r) end @inbounds for i_l in keys(l) @@ -117,7 +117,7 @@ function _innerjoin!(out, l::AbstractArray, r::AbstractArray, v::AbstractArray, dict_index = Base.ht_keyindex(dict, l_value) if dict_index > 0 # -1 if key not found for i_r ∈ dict.vals[dict_index] - push!(out, v[Tuple(i_l)..., Tuple(i_r)...]) + push!(out, v[_tuple(i_l)..., _tuple(i_r)...]) end end end @@ -125,6 +125,9 @@ function _innerjoin!(out, l::AbstractArray, r::AbstractArray, v::AbstractArray, return out end +_tuple(i::Integer) = (i,) +_tuple(i::Any) = Tuple(i) + # TODO more specialized methods for comparisons: ==, <, isless, etc - via sorting strategies