Skip to content

Commit

Permalink
Implement specialized _findin when second arg is AbstractSet
Browse files Browse the repository at this point in the history
  • Loading branch information
garrison committed Feb 21, 2025
1 parent 8b9a19f commit 8826912
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2809,14 +2809,14 @@ function indexin(a, b::AbstractArray)
]
end

function _findin(a::Union{AbstractArray, Tuple}, b)
function _findin(a::Union{AbstractArray, Tuple}, b::AbstractSet)
ind = Vector{eltype(keys(a))}()
bset = Set(b)
@inbounds for (i,ai) in pairs(a)
ai in bset && push!(ind, i)
ai in b && push!(ind, i)
end
ind
end
_findin(a::Union{AbstractArray, Tuple}, b) = _findin(a, Set(b))

# If two collections are already sorted, _findin can be computed with
# a single traversal of the two collections. This is much faster than
Expand Down

0 comments on commit 8826912

Please sign in to comment.