diff --git a/.github/workflows/test-linux-mac.yml b/.github/workflows/test-linux-mac.yml index 4dcc5c3..6d6a3bc 100644 --- a/.github/workflows/test-linux-mac.yml +++ b/.github/workflows/test-linux-mac.yml @@ -23,16 +23,17 @@ jobs: - "1.10" - "nightly" os: - - macos-14 + - macos-13 - ubuntu-latest arch: - x64 - - aarch64 - exclude: - - os: ubuntu-latest + include: + - os: macos-14 arch: aarch64 - - version: 1.6 + version: "1.10" + - os: macos-14 arch: aarch64 + version: "nightly" steps: - uses: actions/checkout@v4 with: diff --git a/src/CxxWrap.jl b/src/CxxWrap.jl index 4640b96..977bc86 100644 --- a/src/CxxWrap.jl +++ b/src/CxxWrap.jl @@ -940,8 +940,8 @@ ConstCxxPtr, ConstCxxRef, CxxRef, CxxPtr, CppEnum, ConstArray, CxxBool, CxxLong, CxxULong, CxxChar, CxxChar16, CxxChar32, CxxWchar, CxxUChar, CxxSignedChar, CxxLongLong, CxxULongLong, ptrunion, gcprotect, gcunprotect, isnull -using .StdLib: StdVector, StdString, StdWString, StdValArray, StdThread, StdDeque, StdQueue, StdSet, StdMultiset +using .StdLib: StdVector, StdString, StdWString, StdValArray, StdThread, StdDeque, StdQueue, StdSet, StdMultiset, StdUnorderedSet, StdUnorderedMultiset -export StdLib, StdVector, StdString, StdWString, StdValArray, StdThread, StdDeque, StdQueue, StdSet, StdMultiset +export StdLib, StdVector, StdString, StdWString, StdValArray, StdThread, StdDeque, StdQueue, StdSet, StdMultiset, StdUnorderedSet, StdUnorderedMultiset end # module diff --git a/src/StdLib.jl b/src/StdLib.jl index a31647f..7b1425c 100644 --- a/src/StdLib.jl +++ b/src/StdLib.jl @@ -209,22 +209,26 @@ Base.push!(v::StdQueue, x) = push_back!(v, x) Base.first(v::StdQueue) = front(v) Base.pop!(v::StdQueue) = pop_front!(v) -Base.size(v::StdSet) = (Int(cppsize(v)),) -Base.length(v::StdSet) = Int(cppsize(v)) -Base.isempty(v::StdSet) = set_isempty(v) -Base.empty!(v::StdSet) = (set_empty!(v); v) -Base.push!(v::StdSet, x) = (set_insert!(v, x); v) -Base.in(x, v::StdSet) = set_in(v, x) -Base.delete!(v::StdSet, x) = (set_delete!(v, x); v) - -Base.size(v::StdMultiset) = (Int(cppsize(v)),) -Base.length(v::StdMultiset) = Int(cppsize(v)) -Base.isempty(v::StdMultiset) = multiset_isempty(v) -Base.empty!(v::StdMultiset) = (multiset_empty!(v); v) -Base.push!(v::StdMultiset, x) = (multiset_insert!(v, x); v) -Base.in(x, v::StdMultiset) = multiset_in(v, x) -Base.delete!(v::StdMultiset, x) = (multiset_delete!(v, x); v) -Base.count(x, v::StdMultiset) = multiset_count(v, x) +for StdSetType in (StdSet, StdUnorderedSet) + Base.size(v::StdSetType) = (Int(cppsize(v)),) + Base.length(v::StdSetType) = Int(cppsize(v)) + Base.isempty(v::StdSetType) = set_isempty(v) + Base.empty!(v::StdSetType) = (set_empty!(v); v) + Base.push!(v::StdSetType, x) = (set_insert!(v, x); v) + Base.in(x, v::StdSetType) = set_in(v, x) + Base.delete!(v::StdSetType, x) = (set_delete!(v, x); v) +end + +for StdMultisetType in (StdMultiset, StdUnorderedMultiset) + Base.size(v::StdMultisetType) = (Int(cppsize(v)),) + Base.length(v::StdMultisetType) = Int(cppsize(v)) + Base.isempty(v::StdMultisetType) = multiset_isempty(v) + Base.empty!(v::StdMultisetType) = (multiset_empty!(v); v) + Base.push!(v::StdMultisetType, x) = (multiset_insert!(v, x); v) + Base.in(x, v::StdMultisetType) = multiset_in(v, x) + Base.delete!(v::StdMultisetType, x) = (multiset_delete!(v, x); v) + Base.count(x, v::StdMultisetType) = multiset_count(v, x) +end function Base.fill!(v::T, x) where T <: Union{StdVector, StdValArray, StdDeque} StdFill(v, x) diff --git a/test/stdlib.jl b/test/stdlib.jl index ae7d0ac..02932b6 100644 --- a/test/stdlib.jl +++ b/test/stdlib.jl @@ -327,110 +327,114 @@ let @test length(queue) == 1 end -@testset "StdSet" begin - @testset "Set with integers" begin - set = StdSet{Int64}() - @test isempty(set) == true - @test length(set) == 0 - set = push!(set, 10) - push!(set, 20) - @test isempty(set) == false - @test length(set) == 2 - @test (10 ∈ set) == true - @test (20 ∈ set) == true - set = delete!(set, 20) - @test length(set) == 1 - @test (20 ∈ set) == false - @test (30 ∈ set) == false - empty!(set) - @test isempty(set) == true - end +@testset "StdSet and StdUnorderedSet" begin + for StdSetType in (StdSet, StdUnorderedSet) + @testset "Set with integers" begin + set = StdSetType{Int64}() + @test isempty(set) == true + @test length(set) == 0 + set = push!(set, 10) + push!(set, 20) + @test isempty(set) == false + @test length(set) == 2 + @test (10 ∈ set) == true + @test (20 ∈ set) == true + set = delete!(set, 20) + @test length(set) == 1 + @test (20 ∈ set) == false + @test (30 ∈ set) == false + empty!(set) + @test isempty(set) == true + end - @testset "Set with bools" begin - set = StdSet{CxxBool}() - @test isempty(set) == true - @test length(set) == 0 - push!(set, true) - push!(set, false) - @test isempty(set) == false - @test length(set) == 2 - @test (true ∈ set) == true - @test (false ∈ set) == true - set = empty!(set) - @test isempty(set) == true - end + @testset "Set with bools" begin + set = StdSetType{CxxBool}() + @test isempty(set) == true + @test length(set) == 0 + push!(set, true) + push!(set, false) + @test isempty(set) == false + @test length(set) == 2 + @test (true ∈ set) == true + @test (false ∈ set) == true + set = empty!(set) + @test isempty(set) == true + end - @testset "Set with floats" begin - set = StdSet{Float64}() - @test isempty(set) == true - @test length(set) == 0 - push!(set, 1.4) - push!(set, 2.2) - @test isempty(set) == false - @test length(set) == 2 - @test (1.4 ∈ set) == true - @test (10.0 ∈ set) == false - @test (2.2 ∈ set) == true - empty!(set) - @test isempty(set) == true + @testset "Set with floats" begin + set = StdSetType{Float64}() + @test isempty(set) == true + @test length(set) == 0 + push!(set, 1.4) + push!(set, 2.2) + @test isempty(set) == false + @test length(set) == 2 + @test (1.4 ∈ set) == true + @test (10.0 ∈ set) == false + @test (2.2 ∈ set) == true + empty!(set) + @test isempty(set) == true + end end end -@testset "StdMultiset" begin - @testset "Multiset with integers" begin - multiset = StdMultiset{Int64}() - @test isempty(multiset) == true - @test length(multiset) == 0 - multiset = push!(multiset, 10) - push!(multiset, 20) - push!(multiset, 20) - count(20, multiset) == 2 - @test isempty(multiset) == false - @test length(multiset) == 3 - @test (10 ∈ multiset) == true - @test (20 ∈ multiset) == true - multiset = delete!(multiset, 20) - @test length(multiset) == 1 - @test (20 ∈ multiset) == false - @test (30 ∈ multiset) == false - empty!(multiset) - @test isempty(multiset) == true - end - - @testset "Multiset with bools" begin - multiset = StdMultiset{CxxBool}() - push!(multiset, true) - push!(multiset, true) - push!(multiset, true) - push!(multiset, false) - @test isempty(multiset) == false - @test count(true, multiset) == 3 - @test count(false, multiset) == 1 - @test length(multiset) == 4 - multiset = delete!(multiset, true) - @test length(multiset) == 1 - multiset = empty!(multiset) - @test length(multiset) == 0 - @test isempty(multiset) == true - end - - @testset "Multiset with floats" begin - multiset = StdMultiset{Float64}() - @test isempty(multiset) == true - @test length(multiset) == 0 - push!(multiset, 1.4) - push!(multiset, 2.2) - push!(multiset, 2.2) - @test isempty(multiset) == false - @test length(multiset) == 3 - @test (1.4 ∈ multiset) == true - @test count(1.4, multiset) == 1 - @test (10.0 ∈ multiset) == false - @test count(10.0, multiset) == 0 - @test (2.2 ∈ multiset) == true - @test count(2.2, multiset) == 2 - empty!(multiset) - @test isempty(multiset) == true +@testset "StdMultiset and StdUnorderedMultiset" begin + for StdMultisetType in (StdMultiset, StdUnorderedMultiset) + @testset "Multiset with integers" begin + multiset = StdMultisetType{Int64}() + @test isempty(multiset) == true + @test length(multiset) == 0 + multiset = push!(multiset, 10) + push!(multiset, 20) + push!(multiset, 20) + count(20, multiset) == 2 + @test isempty(multiset) == false + @test length(multiset) == 3 + @test (10 ∈ multiset) == true + @test (20 ∈ multiset) == true + multiset = delete!(multiset, 20) + @test length(multiset) == 1 + @test (20 ∈ multiset) == false + @test (30 ∈ multiset) == false + empty!(multiset) + @test isempty(multiset) == true + end + + @testset "Multiset with bools" begin + multiset = StdMultisetType{CxxBool}() + push!(multiset, true) + push!(multiset, true) + push!(multiset, true) + push!(multiset, false) + @test isempty(multiset) == false + @test count(true, multiset) == 3 + @test count(false, multiset) == 1 + @test length(multiset) == 4 + multiset = delete!(multiset, true) + @test length(multiset) == 1 + multiset = empty!(multiset) + @test length(multiset) == 0 + @test isempty(multiset) == true + end + + @testset "Multiset with floats" begin + multiset = StdMultisetType{Float64}() + @test isempty(multiset) == true + @test length(multiset) == 0 + push!(multiset, 1.4) + push!(multiset, 2.2) + push!(multiset, 2.2) + @test isempty(multiset) == false + @test length(multiset) == 3 + @test (1.4 ∈ multiset) == true + @test count(1.4, multiset) == 1 + @test (10.0 ∈ multiset) == false + @test count(10.0, multiset) == 0 + @test (2.2 ∈ multiset) == true + @test count(2.2, multiset) == 2 + empty!(multiset) + @test isempty(multiset) == true + end end end