JuliaCollections/OrderedCollections.jl

fast getindex?

Opened this issue · 0 comments

It's a bit unfortunate that we had to deprecate the fast lookup in getindex (ref: JuliaCollections/DataStructures.jl#180)

I have a need to create a subset of an OrderedSet but it's quite inefficient to do that via iteration, turning a O(N) algorithm into O(N^2):

function Base.getindex(os::OrderedSet, indices::AbstractVector{T}) where {T <: Integer}
    new_os = empty(os)
    for i in indices
        for (j, rf) in enumerate(os)
            if  j == i
                push!(new_os, rf)
            end
        end
    end
    return new_os
end

could have been rewritten as

function Base.getindex(os::OrderedSet, indices::AbstractVector{T}) where {T <: Integer}
    return getindex.(Ref(os), indices)
end

Any thoughts about making fast lookup available again?