Skip to content

Commit 73775a2

Browse files
author
Pietro Vertechi
authored
Merge pull request JuliaArrays#5 from KristofferC/kc/resize
implement resize!
2 parents 9b97568 + fcb321f commit 73775a2

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/structarray.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ function cat(dims, args::StructArray...)
7676
StructArray{T}(map(f, fields(eltype(args[1]))))
7777
end
7878

79+
function Base.resize!(s::StructArray, i::Integer)
80+
for a in columns(s)
81+
resize!(a, i)
82+
end
83+
return s
84+
end
85+
7986
for op in [:hcat, :vcat]
8087
@eval begin
8188
function $op(args::StructArray...)

test/runtests.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ end
1818
@test view(t, 2, 1:2) == StructArray{ComplexF64}(view(a, 2, 1:2), view(b, 2, 1:2))
1919
end
2020

21+
@testset "resize!" begin
22+
t = StructArray{Pair}([3, 5], ["a", "b"])
23+
resize!(t, 5)
24+
@test length(t) == 5
25+
p = 1 => "c"
26+
t[5] = p
27+
@test t[5] == p
28+
end
29+
2130
@testset "concat" begin
2231
t = StructArray{Pair}([3, 5], ["a", "b"])
2332
push!(t, (2 => "c"))

0 commit comments

Comments
 (0)