Skip to content

Commit 950bb88

Browse files
authored
Merge pull request #78 from fredrikekre/fe/push-etc
Define some modifying functions for OffsetVector
2 parents 07f33c3 + 344c1d8 commit 950bb88

File tree

5 files changed

+29
-8
lines changed

5 files changed

+29
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/Manifest.toml

.travis.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,3 @@ julia:
1212

1313
notifications:
1414
email: false
15-
16-
after_success:
17-
- julia -e 'Pkg.init(); run(`ln -s $(pwd()) $(Pkg.dir("OffsetArrays"))`); Pkg.pin("OffsetArrays"); Pkg.resolve()'
18-
- julia -e 'using OffsetArrays; @assert isdefined(:OffsetArrays); @assert typeof(OffsetArrays) === Module'

Project.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
name = "OffsetArrays"
22
uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
3-
version = "0.11.0"
4-
5-
[deps]
6-
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
3+
version = "0.11.1"
74

85
[compat]
96
julia = "0.7, 1"

src/OffsetArrays.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,13 @@ Base.fill(x, inds::Tuple{UnitRange,Vararg{UnitRange}}) =
195195
fill!(OffsetArray{typeof(x)}(undef, inds), x)
196196
@inline Base.fill(x, ind1::UnitRange, inds::UnitRange...) = fill(x, (ind1, inds...))
197197

198+
199+
### Some mutating functions defined only for OffsetVector ###
200+
198201
Base.resize!(A::OffsetVector, nl::Integer) = (resize!(A.parent, nl); A)
202+
Base.push!(A::OffsetVector, x...) = (push!(A.parent, x...); A)
203+
Base.pop!(A::OffsetVector) = pop!(A.parent)
204+
Base.empty!(A::OffsetVector) = (empty!(A.parent); A)
199205

200206
### Low-level utilities ###
201207

test/runtests.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,3 +554,24 @@ end
554554
O2[1, 1] = x + 1 # just a sanity check
555555
@test A[2, 2] == x + 1
556556
end
557+
558+
@testset "mutating functions for OffsetVector" begin
559+
# push!
560+
o = OffsetVector(Int[], -1)
561+
@test push!(o) === o
562+
@test axes(o, 1) == 0:-1
563+
@test push!(o, 1) === o
564+
@test axes(o, 1) == 0:0
565+
@test o[end] == 1
566+
@test push!(o, 2, 3) === o
567+
@test axes(o, 1) == 0:2
568+
@test o[end-1:end] == [2, 3]
569+
# pop!
570+
o = OffsetVector([1, 2, 3], -1)
571+
@test pop!(o) == 3
572+
@test axes(o, 1) == 0:1
573+
# empty!
574+
o = OffsetVector([1, 2, 3], -1)
575+
@test empty!(o) === o
576+
@test axes(o, 1) == 0:-1
577+
end

0 commit comments

Comments
 (0)