Skip to content

Commit a0b5d05

Browse files
committed
Update resizable_array.jl
1 parent 2ccd813 commit a0b5d05

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

src/resizable_array.jl

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ end
1717

1818
ResizableArray(::Type{T}) where {T} = ResizableArray{T, Vector{T}, 1}(T[])
1919

20+
similar(::ResizableArray{T, V, N}) where {T, V, N} = ResizableArray(T, Val(N))
21+
2022
function ResizableArray(::Type{T}, ::Val{N}) where {T, N}
2123
data = make_recursive_vector(T, Val(N))
2224
V = typeof(data)
@@ -29,13 +31,16 @@ end
2931

3032
get_recursive_depth(any) = 0
3133

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
3440
end
35-
reltype(any::T) where {T} = T
3641

3742
function ResizableArray(array::AbstractVector{T}) where {T}
38-
V = reltype(array)
43+
V = reltype(typeof(array))
3944
return ResizableArray{V, Vector{T}, get_recursive_depth(array)}(array)
4045
end
4146

@@ -181,14 +186,6 @@ function Base.iterate(array::ResizableArray, state)
181186
return nothing
182187
end
183188
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
192189
return (array[nindex.I...], isnothing(nstate) ? nothing : (indx, nstate))
193190
end
194191

0 commit comments

Comments
 (0)