Skip to content

Added getindex and view for UniqueSortIndex with a UnitRange #11

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

Merged
merged 2 commits into from
May 30, 2020
Merged
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: 14 additions & 1 deletion src/UniqueSortIndex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,19 @@ function Base.findlast(f::Fix2{typeof(in), <:Interval}, a::AcceleratedArray{<:An
end
end

Base.@propagate_inbounds function Base.getindex(a::AcceleratedVector{<:Any, <:Any, <:UniqueSortIndex{<:Base.OneTo}}, ind::AbstractUnitRange{Int})
a_i = getindex(parent(a), ind)
AcceleratedArray(a_i, UniqueSortIndex(Base.OneTo(length(a_i))))
end

Base.@propagate_inbounds function Base.view(a::AcceleratedVector{<:Any, <:Any, <:UniqueSortIndex{<:Base.OneTo}}, ind::AbstractUnitRange{Int})
a_i = view(parent(a), ind)
AcceleratedArray(a_i, UniqueSortIndex(Base.OneTo(length(a_i))))
end

# TODO - Grouping
# - Sort-merge joins
# - Sorted indexing preserves sortedness (including at least unit ranges)
# - Sorted indexing with StepRanges. Have to check step is positive and branch, so not type stable.
# Could allow a wrapper PositiveStep(steprange) that either returns a StepRange or errors, and is therefore type-stable
# Users could then index their AcceleratedArrays with PositiveStep(range) if they cared about stability
# - Sorted indexing with other known-sorted arrays of integers.