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

fast getindex? #24

Open
tk3369 opened this issue Aug 16, 2019 · 0 comments
Open

fast getindex? #24

tk3369 opened this issue Aug 16, 2019 · 0 comments

Comments

@tk3369
Copy link

tk3369 commented Aug 16, 2019

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant