From 9d06993170bcbef11bf41a652112558c492442c8 Mon Sep 17 00:00:00 2001 From: Praneeth Jain Date: Sun, 31 Mar 2024 20:33:33 +0530 Subject: [PATCH] Add StdFill (#420) * feat: fill algorithm * test: StdFill * build: macos-13 * bump: Julia 1.7 * test: switch back to Julia 1.6 * fix: fill! returns the container --- .github/workflows/test-linux-mac.yml | 11 +++++------ .github/workflows/test-win.yml | 23 +++++++++++------------ src/StdLib.jl | 10 ++++++---- test/stdlib.jl | 28 ++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 22 deletions(-) diff --git a/.github/workflows/test-linux-mac.yml b/.github/workflows/test-linux-mac.yml index d610886..2013b78 100644 --- a/.github/workflows/test-linux-mac.yml +++ b/.github/workflows/test-linux-mac.yml @@ -10,7 +10,7 @@ on: defaults: run: shell: bash - + jobs: test: name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} @@ -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 @@ -65,4 +65,3 @@ jobs: cd ../.. - uses: julia-actions/julia-buildpkg@latest - uses: julia-actions/julia-runtest@latest - diff --git a/.github/workflows/test-win.yml b/.github/workflows/test-win.yml index 560c605..7d35a75 100644 --- a/.github/workflows/test-win.yml +++ b/.github/workflows/test-win.yml @@ -10,7 +10,7 @@ on: defaults: run: shell: bash - + jobs: test: name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} @@ -19,9 +19,9 @@ jobs: fail-fast: false matrix: version: - - '1.6' - - '1.10' - - 'nightly' + - "1.7" + - "1.10" + - "nightly" os: - windows-latest arch: @@ -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 - diff --git a/src/StdLib.jl b/src/StdLib.jl index d77afae..225533f 100644 --- a/src/StdLib.jl +++ b/src/StdLib.jl @@ -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)[] @@ -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 diff --git a/test/stdlib.jl b/test/stdlib.jl index 91676b5..7d1d739 100644 --- a/test/stdlib.jl +++ b/test/stdlib.jl @@ -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