@@ -9,10 +9,11 @@ differ in size). Internally, `VectorOfArrays` stores all elements of all
9
9
arrays in a single flat vector. `M` must equal `N - 1`
10
10
11
11
The `VectorOfArrays` itself supports `push!`, `unshift!`, etc., but the size
12
- of each individual array in the vector is fixed. `resize!` is not supported,
13
- as the size of all arrays in the vector must be defined. However, memory space
14
- for up to `n` arrays with a maximum size `s` can be reserved via
15
- `sizehint!(A::VectorOfArrays, n, s::Dims{N})`
12
+ of each individual array in the vector is fixed. `resize!` can be used to
13
+ shrink, but not to grow, as the size of the additional element arrays in the
14
+ vector would be unknown. However, memory space for up to `n` arrays with a
15
+ maximum size `s` can be reserved via
16
+ `sizehint!(A::VectorOfArrays, n, s::Dims{N})`.
16
17
17
18
Constructors:
18
19
218
219
Base. length (A:: VectorOfArrays ) = length (A. kernel_size)
219
220
220
221
222
+ @inline function Base. resize! (A:: VectorOfArrays{T,N,M} , n:: Integer ) where {T,M,N}
223
+ old_n = length (A)
224
+ if n > old_n
225
+ throw (ArgumentError (" Cannot resize VectorOfArrays from length $old_n to $n , can only shrink, not grow" ))
226
+ elseif n < old_n
227
+ resize! (A. data, A. elem_ptr[n+ 1 ] - 1 )
228
+ resize! (A. elem_ptr, n + 1 )
229
+ resize! (A. kernel_size, n)
230
+ end
231
+ A
232
+ end
233
+
234
+
221
235
function Base. append! (A:: VectorOfArrays{T,N} , B:: VectorOfArrays{U,N} ) where {T,N,U}
222
236
if ! isempty (B)
223
237
# Implementation supports A === B
0 commit comments