Skip to content
Open
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
36 changes: 36 additions & 0 deletions src/group.jl
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,42 @@

@deprecate groupinds groupfind

function groupfind2(array::AbstractArray)
# In a single pass we collect the size of each group and the token to which group each element belongs
group_sizes = Dictionary{eltype(array), Int}()
to_group_token = similar(array, Int)

@inbounds for i in eachindex(array)
value = array[i]
(hadindex, token) = gettoken!(group_sizes, value)
dict_index = token[2]
if hadindex
settokenvalue!(group_sizes, token, gettokenvalue(group_sizes, token) + 1)
else
settokenvalue!(group_sizes, token, 1)
end
to_group_token[i] = dict_index # Insertion-only, the token is stable...
end

Check warning on line 290 in src/group.jl

View check run for this annotation

Codecov / codecov/patch

src/group.jl#L274-L290

Added lines #L274 - L290 were not covered by tests
# We find the sort permutation and the ranges of the sort permutation for each group
sorted_indices = sortperm(to_group_token)

this_start = 1
this_stop = 0
ranges = similar(group_sizes, UnitRange{Int})
@inbounds for token in tokens(group_sizes)
this_size = gettokenvalue(group_sizes, token)
this_stop += this_size
settokenvalue!(ranges, token, this_start:this_stop)
this_start += this_size
end

Check warning on line 303 in src/group.jl

View check run for this annotation

Codecov / codecov/patch

src/group.jl#L292-L303

Added lines #L292 - L303 were not covered by tests
# We lazily index these ranges onto sorted_indices
return mapview((r -> @inbounds(view(sorted_indices, r))), ranges)
end

Check warning on line 306 in src/group.jl

View check run for this annotation

Codecov / codecov/patch

src/group.jl#L305-L306

Added lines #L305 - L306 were not covered by tests



"""
groupfind([by], container)

Expand Down