|
17 | 17 |
|
18 | 18 | ResizableArray(::Type{T}) where {T} = ResizableArray{T, Vector{T}, 1}(T[]) |
19 | 19 |
|
| 20 | +similar(::ResizableArray{T, V, N}) where {T, V, N} = ResizableArray(T, Val(N)) |
| 21 | + |
20 | 22 | function ResizableArray(::Type{T}, ::Val{N}) where {T, N} |
21 | 23 | data = make_recursive_vector(T, Val(N)) |
22 | 24 | V = typeof(data) |
|
29 | 31 |
|
30 | 32 | get_recursive_depth(any) = 0 |
31 | 33 |
|
32 | | -function reltype(v::AbstractVector) |
33 | | - return reltype(first(v)) |
| 34 | +function reltype(::Type{<:AbstractVector{<:T}}) where {T <: AbstractArray} |
| 35 | + return reltype(T) |
| 36 | +end |
| 37 | + |
| 38 | +function reltype(::Type{<:AbstractVector{T}}) where {T} |
| 39 | + return T |
34 | 40 | end |
35 | | -reltype(any::T) where {T} = T |
36 | 41 |
|
37 | 42 | function ResizableArray(array::AbstractVector{T}) where {T} |
38 | | - V = reltype(array) |
| 43 | + V = reltype(typeof(array)) |
39 | 44 | return ResizableArray{V, Vector{T}, get_recursive_depth(array)}(array) |
40 | 45 | end |
41 | 46 |
|
@@ -181,14 +186,6 @@ function Base.iterate(array::ResizableArray, state) |
181 | 186 | return nothing |
182 | 187 | end |
183 | 188 | nindex, nstate = niterate |
184 | | - while !isassigned(array, nindex.I...) |
185 | | - pstate = nstate |
186 | | - niterate = iterate(indx, pstate) |
187 | | - if isnothing(niterate) |
188 | | - return nothing |
189 | | - end |
190 | | - nindex, nstate = niterate |
191 | | - end |
192 | 189 | return (array[nindex.I...], isnothing(nstate) ? nothing : (indx, nstate)) |
193 | 190 | end |
194 | 191 |
|
|
0 commit comments