Skip to content

Commit 7a1507b

Browse files
committed
Added getindex and view for UniqueSortIndex with a UnitRange
1 parent 1f3cd80 commit 7a1507b

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
@@ -326,6 +326,19 @@ function Base.findlast(f::Fix2{typeof(in), <:Interval}, a::AcceleratedArray{<:An
326326
end
327327
end
328328

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

0 commit comments

Comments
 (0)