Skip to content

Commit db749b4

Browse files
authored
Merge pull request #11 from kcajf/sorted-getindex
Added getindex and view for UniqueSortIndex with a UnitRange
2 parents 736d509 + c2e8e58 commit db749b4

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/UniqueSortIndex.jl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,19 @@ function Base.findlast(f::Fix2{typeof(in), <:Interval}, a::AcceleratedArray{<:An
333333
end
334334
end
335335

336+
Base.@propagate_inbounds function Base.getindex(a::AcceleratedVector{<:Any, <:Any, <:UniqueSortIndex{<:Base.OneTo}}, ind::AbstractUnitRange{Int})
337+
a_i = getindex(parent(a), ind)
338+
AcceleratedArray(a_i, UniqueSortIndex(Base.OneTo(length(a_i))))
339+
end
340+
341+
Base.@propagate_inbounds function Base.view(a::AcceleratedVector{<:Any, <:Any, <:UniqueSortIndex{<:Base.OneTo}}, ind::AbstractUnitRange{Int})
342+
a_i = view(parent(a), ind)
343+
AcceleratedArray(a_i, UniqueSortIndex(Base.OneTo(length(a_i))))
344+
end
345+
336346
# TODO - Grouping
337347
# - Sort-merge joins
338-
# - Sorted indexing preserves sortedness (including at least unit ranges)
348+
# - Sorted indexing with StepRanges. Have to check step is positive and branch, so not type stable.
349+
# Could allow a wrapper PositiveStep(steprange) that either returns a StepRange or errors, and is therefore type-stable
350+
# Users could then index their AcceleratedArrays with PositiveStep(range) if they cared about stability
351+
# - Sorted indexing with other known-sorted arrays of integers.

0 commit comments

Comments
 (0)