@@ -14,23 +14,25 @@ function Base.permute!(c::StructVector, p::AbstractVector)
14
14
return c
15
15
end
16
16
17
- struct TiedIndices{T <: AbstractVector }
17
+ struct TiedIndices{T<: AbstractVector , U <: AbstractUnitRange }
18
18
vec:: T
19
19
perm:: Vector{Int}
20
- within:: Tuple{Int, Int}
20
+ within:: U
21
21
end
22
22
23
23
TiedIndices (vec:: AbstractVector , perm= sortperm (vec)) =
24
- TiedIndices (vec, perm, extrema ( axes (vec, 1 ) ))
24
+ TiedIndices (vec, perm, axes (vec, 1 ))
25
25
26
26
Base. IteratorSize (:: Type{<:TiedIndices} ) = Base. SizeUnknown ()
27
27
28
28
Base. eltype (:: Type{<:TiedIndices{T}} ) where {T} =
29
29
Pair{eltype (T), UnitRange{Int}}
30
30
31
- function Base. iterate (n:: TiedIndices , i = n. within[1 ])
31
+ Base. sortperm (t:: TiedIndices ) = t. perm
32
+
33
+ function Base. iterate (n:: TiedIndices , i = first (n. within))
32
34
vec, perm = n. vec, n. perm
33
- l = n. within[ 2 ]
35
+ l = last ( n. within)
34
36
i > l && return nothing
35
37
row = vec[perm[i]]
36
38
i1 = i
42
44
43
45
tiedindices (args... ) = TiedIndices (args... )
44
46
45
- function groupindices (args... )
47
+ function uniquesorted (args... )
48
+ t = tiedindices (args... )
49
+ (row for (row, _) in t)
50
+ end
51
+
52
+ function finduniquesorted (args... )
46
53
t = tiedindices (args... )
47
- p = t . perm
48
- (( row => t . perm [idxs]) for (row, idxs) in t)
54
+ p = sortperm (t)
55
+ (row => p [idxs] for (row, idxs) in t)
49
56
end
50
57
51
58
function Base. sortperm (c:: StructVector{T} ;
@@ -70,7 +77,7 @@ function refine_perm!(p, cols, c, x, y, lo, hi)
70
77
temp = similar (p, 0 )
71
78
order = Base. Order. By (j-> (@inbounds k= y[j]; k))
72
79
nc = length (cols)
73
- for (_, idxs) in TiedIndices (x, p, (lo, hi) )
80
+ for (_, idxs) in TiedIndices (x, p, lo : hi )
74
81
i, i1 = extrema (idxs)
75
82
if i1 > i
76
83
sort_sub_by! (p, i, i1, y, order, temp)
0 commit comments