|
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 |
|
@@ -184,11 +189,6 @@ function Base.iterate(array::ResizableArray, state) |
184 | 189 | return (array[nindex.I...], isnothing(nstate) ? nothing : (indx, nstate)) |
185 | 190 | end |
186 | 191 |
|
187 | | -function Base.map(f, array::ResizableArray{T, V, N}) where {T, V, N} |
188 | | - result = map(f, array.data) |
189 | | - return ResizableArray(result) |
190 | | -end |
191 | | - |
192 | 192 | __length(array::ResizableArray{T, V, N}) where {T, V, N} = __recursive_length(Val(N), array.data) |
193 | 193 |
|
194 | 194 | function __recursive_length(::Val{N}, array) where {N} |
|
241 | 241 | function lastwithindex(array::ResizableArray{T, V, N}) where {T, V, N} |
242 | 242 | for index in reverse(CartesianIndices(reverse(size(array)))) #TODO improve performance of this function since it uses splatting |
243 | 243 | if isassigned(array, reverse(index.I)...)::Bool |
244 | | - return (index, array[reverse(index.I)...]) |
| 244 | + return (CartesianIndex(reverse(index.I)), array[reverse(index.I)...]) |
245 | 245 | end |
246 | 246 | end |
247 | 247 | end |
0 commit comments