Skip to content

Commit

Permalink
Add StdFill (#420)
Browse files Browse the repository at this point in the history
* feat: fill algorithm

* test: StdFill

* build: macos-13

* bump: Julia 1.7

* test: switch back to Julia 1.6

* fix: fill! returns the container
  • Loading branch information
PraneethJain authored Mar 31, 2024
1 parent c445909 commit 9d06993
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 22 deletions.
11 changes: 5 additions & 6 deletions .github/workflows/test-linux-mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
defaults:
run:
shell: bash

jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }}
Expand All @@ -19,11 +19,11 @@ jobs:
fail-fast: false
matrix:
version:
- '1.6'
- '1.10'
- 'nightly'
- "1.6"
- "1.10"
- "nightly"
os:
- macOS-latest
- macos-13
- ubuntu-latest
arch:
- x64
Expand Down Expand Up @@ -65,4 +65,3 @@ jobs:
cd ../..
- uses: julia-actions/julia-buildpkg@latest
- uses: julia-actions/julia-runtest@latest

23 changes: 11 additions & 12 deletions .github/workflows/test-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
defaults:
run:
shell: bash

jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }}
Expand All @@ -19,9 +19,9 @@ jobs:
fail-fast: false
matrix:
version:
- '1.6'
- '1.10'
- 'nightly'
- "1.7"
- "1.10"
- "nightly"
os:
- windows-latest
arch:
Expand Down Expand Up @@ -58,20 +58,19 @@ jobs:
continue-on-error: true
if: ${{ matrix.arch == 'x86'}}
run: |
cd libcxxwrap && mkdir build && cd build
cmake -G "Visual Studio 17 2022" -A Win32 -DOVERRIDES_PATH=$HOMEDRIVE/$HOMEPATH/.julia/artifacts/Overrides.toml -DOVERRIDE_ROOT=./ -DAPPEND_OVERRIDES_TOML=ON ..
cd libcxxwrap && mkdir build && cd build
cmake -G "Visual Studio 17 2022" -A Win32 -DOVERRIDES_PATH=$HOMEDRIVE/$HOMEPATH/.julia/artifacts/Overrides.toml -DOVERRIDE_ROOT=./ -DAPPEND_OVERRIDES_TOML=ON ..
- name: Config 64bit
continue-on-error: true
if: ${{ matrix.arch == 'x64'}}
run: |
cd libcxxwrap && mkdir build && cd build
cmake -G "Visual Studio 17 2022" -A x64 -DOVERRIDES_PATH=$HOMEDRIVE/$HOMEPATH/.julia/artifacts/Overrides.toml -DOVERRIDE_ROOT=./ -DAPPEND_OVERRIDES_TOML=ON ..
cd libcxxwrap && mkdir build && cd build
cmake -G "Visual Studio 17 2022" -A x64 -DOVERRIDES_PATH=$HOMEDRIVE/$HOMEPATH/.julia/artifacts/Overrides.toml -DOVERRIDE_ROOT=./ -DAPPEND_OVERRIDES_TOML=ON ..
- name: Build libcxxwrap
continue-on-error: true
run: |
cd libcxxwrap/build
cmake --build . --config Release
cd libcxxwrap/build
cmake --build . --config Release
- uses: julia-actions/julia-buildpkg@latest
- uses: julia-actions/julia-runtest@latest

10 changes: 6 additions & 4 deletions src/StdLib.jl
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,6 @@ Base.size(v::StdValArray) = (Int(cppsize(v)),)
Base.getindex(v::StdValArray, i::Int) = cxxgetindex(v,i)[]
Base.setindex!(v::StdValArray{T}, val, i::Int) where {T} = cxxsetindex!(v, convert(T,val), i)

function StdDeque(v::Vector{T}) where {T}
return StdDeque{T}(v, length(v))
end

Base.IndexStyle(::Type{<:StdDeque}) = IndexLinear()
Base.size(v::StdDeque) = (Int(cppsize(v)),)
Base.getindex(v::StdDeque, i::Int) = cxxgetindex(v,i)[]
Expand All @@ -212,4 +208,10 @@ Base.size(v::StdQueue) = (Int(cppsize(v)),)
Base.push!(v::StdQueue, x) = push_back!(v, x)
Base.first(v::StdQueue) = front(v)
Base.pop!(v::StdQueue) = pop_front!(v)

function Base.fill!(v::T, x) where T <: Union{StdVector, StdValArray, StdDeque}
StdFill(v, x)
return v
end

end
28 changes: 28 additions & 0 deletions test/stdlib.jl
Original file line number Diff line number Diff line change
Expand Up @@ -327,4 +327,32 @@ let
@test length(queue) == 1
end

@testset "StdFill" begin
@testset "fill StdVector" begin
v = StdVector{Int64}([1, 2, 3, 4, 5])
fill!(v, 1)
for x in v
@test x == 1
end
end

@testset "fill StdValArray" begin
v = StdValArray([1.0, 2.0, 3.0])
fill!(v, 2)
for x in v
@test x == 2
end
end

@testset "fill StdDeque" begin
deq = StdDeque{Int64}()
for i = 1:10
push!(deq, i)
end
fill!(deq, 3)
for x in deq
@test x == 3
end
end
end
end

0 comments on commit 9d06993

Please sign in to comment.