diff --git a/base/dates/query.jl b/base/dates/query.jl index 64ae360a7b275..b3fe9e3f9a996 100644 --- a/base/dates/query.jl +++ b/base/dates/query.jl @@ -157,9 +157,9 @@ end # Total number of a day of week in the month # e.g. are there 4 or 5 Mondays in this month? -const TWENTYNINE = IntSet([1, 8, 15, 22, 29]) -const THIRTY = IntSet([1, 2, 8, 9, 15, 16, 22, 23, 29, 30]) -const THIRTYONE = IntSet([1, 2, 3, 8, 9, 10, 15, 16, 17, 22, 23, 24, 29, 30, 31]) +const TWENTYNINE = PositiveIntSet([1, 8, 15, 22, 29]) +const THIRTY = PositiveIntSet([1, 2, 8, 9, 15, 16, 22, 23, 29, 30]) +const THIRTYONE = PositiveIntSet([1, 2, 3, 8, 9, 10, 15, 16, 17, 22, 23, 24, 29, 30, 31]) """ daysofweekinmonth(dt::TimeType) -> Int diff --git a/base/deprecated.jl b/base/deprecated.jl index 9db39ec2b8eda..1f8981a2e0921 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -1221,6 +1221,8 @@ function (::Type{Matrix})() return Matrix(0, 0) end +@deprecate_binding IntSet PositiveIntSet + for name in ("alnum", "alpha", "cntrl", "digit", "number", "graph", "lower", "print", "punct", "space", "upper", "xdigit") f = Symbol("is",name) diff --git a/base/docs/helpdb/Base.jl b/base/docs/helpdb/Base.jl index b79496acbfee0..eadcadfc1b05c 100644 --- a/base/docs/helpdb/Base.jl +++ b/base/docs/helpdb/Base.jl @@ -1450,14 +1450,14 @@ The arguments to a function or constructor are outside the valid domain. DomainError """ - IntSet([itr]) + PositiveIntSet([itr]) Construct a sorted set of positive `Int`s generated by the given iterable object, or an empty set. Implemented as a bit string, and therefore designed for dense integer sets. Only `Int`s greater than 0 can be stored. If the set will be sparse (for example holding a few very large integers), use [`Set`](@ref) instead. """ -IntSet +PositiveIntSet """ Task(func) @@ -2379,7 +2379,7 @@ widen Set([itr]) Construct a [`Set`](@ref) of the values generated by the given iterable object, or an -empty set. Should be used instead of [`IntSet`](@ref) for sparse integer sets, or +empty set. Should be used instead of [`PositiveIntSet`](@ref) for sparse integer sets, or for sets of arbitrary objects. """ Set diff --git a/base/exports.jl b/base/exports.jl index 78b9ee477cc2b..70fdae7bade2e 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -67,7 +67,7 @@ export Hermitian, UniformScaling, InsertionSort, - IntSet, + PositiveIntSet, IOBuffer, IOStream, LinSpace, diff --git a/base/inference.jl b/base/inference.jl index 3e76d2d196a58..6485b3eb2092b 100644 --- a/base/inference.jl +++ b/base/inference.jl @@ -115,7 +115,7 @@ type InferenceState # return type bestguess #::Type # current active instruction pointers - ip::IntSet + ip::PositiveIntSet pc´´::Int nstmts::Int # current exception handler info @@ -123,7 +123,7 @@ type InferenceState handler_at::Vector{Any} n_handlers::Int # ssavalue sparsity and restart info - ssavalue_uses::Vector{IntSet} + ssavalue_uses::Vector{PositiveIntSet} ssavalue_init::Vector{Any} # call-graph edges connecting from a caller to a callee (and back) # we shouldn't need to iterate edges very often, so we use it to optimize the lookup from edge -> linenum @@ -232,7 +232,7 @@ type InferenceState handler_at = Any[ () for i=1:n ] n_handlers = 0 - W = IntSet() + W = PositiveIntSet() push!(W, 1) #initial pc to visit if !toplevel @@ -2170,7 +2170,7 @@ end genlabel(sv) = LabelNode(sv.label_counter += 1) function find_ssavalue_uses(body) - uses = IntSet[] + uses = PositiveIntSet[] for line = 1:length(body) find_ssavalue_uses(body[line], uses, line) end @@ -2180,7 +2180,7 @@ function find_ssavalue_uses(e::ANY, uses, line) if isa(e,SSAValue) id = (e::SSAValue).id + 1 while length(uses) < id - push!(uses, IntSet()) + push!(uses, PositiveIntSet()) end push!(uses[id], line) elseif isa(e,Expr) @@ -2191,7 +2191,7 @@ function find_ssavalue_uses(e::ANY, uses, line) if isa(b.args[1],SSAValue) id = (b.args[1]::SSAValue).id + 1 while length(uses) < id - push!(uses, IntSet()) + push!(uses, PositiveIntSet()) end end find_ssavalue_uses(b.args[2], uses, line) diff --git a/base/intset.jl b/base/intset.jl index cecbb0f2a365d..aee87e50ba973 100644 --- a/base/intset.jl +++ b/base/intset.jl @@ -1,24 +1,24 @@ # This file is a part of Julia. License is MIT: http://julialang.org/license -immutable IntSet <: AbstractSet{Int} +immutable PositiveIntSet <: AbstractSet{Int} bits::BitVector - IntSet() = new(falses(256)) + PositiveIntSet() = new(falses(256)) end -IntSet(itr) = union!(IntSet(), itr) +PositiveIntSet(itr) = union!(PositiveIntSet(), itr) -eltype(::Type{IntSet}) = Int -similar(s::IntSet) = IntSet() -copy(s1::IntSet) = copy!(IntSet(), s1) -function copy!(dest::IntSet, src::IntSet) +eltype(::Type{PositiveIntSet}) = Int +similar(s::PositiveIntSet) = PositiveIntSet() +copy(s1::PositiveIntSet) = copy!(PositiveIntSet(), s1) +function copy!(dest::PositiveIntSet, src::PositiveIntSet) resize!(dest.bits, length(src.bits)) copy!(dest.bits, src.bits) dest end -eltype(s::IntSet) = Int -sizehint!(s::IntSet, n::Integer) = (_resize0!(s.bits, max(n, length(s.bits))); s) +eltype(s::PositiveIntSet) = Int +sizehint!(s::PositiveIntSet, n::Integer) = (_resize0!(s.bits, max(n, length(s.bits))); s) # An internal function for setting the inclusion bit for a given integer n >= 0 -@inline function _setint!(s::IntSet, idx::Integer, b::Bool) +@inline function _setint!(s::PositiveIntSet, idx::Integer, b::Bool) if idx > length(s.bits) b || return s # setting a bit to zero outside the set's bits is a no-op newlen = idx + idx>>1 # This operation may overflow; we want saturation @@ -52,7 +52,7 @@ function _matched_map!(f, b1::BitArray, b2::BitArray) resize!(b1, l2) map!(f, b1, b1, b2) else - # We transiently extend b2 — as IntSet internal storage this is unobservable + # We transiently extend b2 — as PositiveIntSet internal storage this is unobservable _resize0!(b2, l1) map!(f, b1, b1, b2) resize!(b2, l2) @@ -61,96 +61,96 @@ function _matched_map!(f, b1::BitArray, b2::BitArray) b1 end -@noinline _throw_intset_bounds_err() = throw(ArgumentError("elements of IntSet must be between 1 and typemax(Int)")) +@noinline _throw_intset_bounds_err() = throw(ArgumentError("elements of PositiveIntSet must be between 1 and typemax(Int)")) @noinline _throw_keyerror(n) = throw(KeyError(n)) -@inline function push!(s::IntSet, n::Integer) +@inline function push!(s::PositiveIntSet, n::Integer) 0 < n <= typemax(Int) || _throw_intset_bounds_err() _setint!(s, n, true) end -push!(s::IntSet, ns::Integer...) = (for n in ns; push!(s, n); end; s) +push!(s::PositiveIntSet, ns::Integer...) = (for n in ns; push!(s, n); end; s) -@inline function pop!(s::IntSet) +@inline function pop!(s::PositiveIntSet) pop!(s, last(s)) end -@inline function pop!(s::IntSet, n::Integer) +@inline function pop!(s::PositiveIntSet, n::Integer) n in s ? (_delete!(s, n); n) : _throw_keyerror(n) end -@inline function pop!(s::IntSet, n::Integer, default) +@inline function pop!(s::PositiveIntSet, n::Integer, default) n in s ? (_delete!(s, n); n) : default end -@inline _delete!(s::IntSet, n::Integer) = _setint!(s, n, false) -@inline delete!(s::IntSet, n::Integer) = n < 0 ? s : _delete!(s, n) -shift!(s::IntSet) = pop!(s, first(s)) +@inline _delete!(s::PositiveIntSet, n::Integer) = _setint!(s, n, false) +@inline delete!(s::PositiveIntSet, n::Integer) = n < 0 ? s : _delete!(s, n) +shift!(s::PositiveIntSet) = pop!(s, first(s)) -empty!(s::IntSet) = (fill!(s.bits, false); s) -isempty(s::IntSet) = !any(s.bits) +empty!(s::PositiveIntSet) = (fill!(s.bits, false); s) +isempty(s::PositiveIntSet) = !any(s.bits) # Mathematical set functions: union!, intersect!, setdiff!, symdiff! -union(s::IntSet) = copy(s) -union(s1::IntSet, s2::IntSet) = union!(copy(s1), s2) -union(s1::IntSet, ss::IntSet...) = union(s1, union(ss...)) -union(s::IntSet, ns) = union!(copy(s), ns) -union!(s::IntSet, ns) = (for n in ns; push!(s, n); end; s) -function union!(s1::IntSet, s2::IntSet) +union(s::PositiveIntSet) = copy(s) +union(s1::PositiveIntSet, s2::PositiveIntSet) = union!(copy(s1), s2) +union(s1::PositiveIntSet, ss::PositiveIntSet...) = union(s1, union(ss...)) +union(s::PositiveIntSet, ns) = union!(copy(s), ns) +union!(s::PositiveIntSet, ns) = (for n in ns; push!(s, n); end; s) +function union!(s1::PositiveIntSet, s2::PositiveIntSet) _matched_map!(|, s1.bits, s2.bits) s1 end -intersect(s1::IntSet) = copy(s1) -intersect(s1::IntSet, ss::IntSet...) = intersect(s1, intersect(ss...)) -function intersect(s1::IntSet, ns) - s = IntSet() +intersect(s1::PositiveIntSet) = copy(s1) +intersect(s1::PositiveIntSet, ss::PositiveIntSet...) = intersect(s1, intersect(ss...)) +function intersect(s1::PositiveIntSet, ns) + s = PositiveIntSet() for n in ns n in s1 && push!(s, n) end s end -intersect(s1::IntSet, s2::IntSet) = +intersect(s1::PositiveIntSet, s2::PositiveIntSet) = (length(s1.bits) >= length(s2.bits) ? intersect!(copy(s1), s2) : intersect!(copy(s2), s1)) """ - intersect!(s1::IntSet, s2::IntSet) + intersect!(s1::PositiveIntSet, s2::PositiveIntSet) Intersects sets `s1` and `s2` and overwrites the set `s1` with the result. If needed, `s1` will be expanded to the size of `s2`. """ -function intersect!(s1::IntSet, s2::IntSet) +function intersect!(s1::PositiveIntSet, s2::PositiveIntSet) _matched_map!(&, s1.bits, s2.bits) s1 end -setdiff(s::IntSet, ns) = setdiff!(copy(s), ns) -setdiff!(s::IntSet, ns) = (for n in ns; _delete!(s, n); end; s) -function setdiff!(s1::IntSet, s2::IntSet) +setdiff(s::PositiveIntSet, ns) = setdiff!(copy(s), ns) +setdiff!(s::PositiveIntSet, ns) = (for n in ns; _delete!(s, n); end; s) +function setdiff!(s1::PositiveIntSet, s2::PositiveIntSet) _matched_map!(>, s1.bits, s2.bits) s1 end -symdiff(s::IntSet, ns) = symdiff!(copy(s), ns) +symdiff(s::PositiveIntSet, ns) = symdiff!(copy(s), ns) """ symdiff!(s, itr) For each element in `itr`, destructively toggle its inclusion in set `s`. """ -symdiff!(s::IntSet, ns) = (for n in ns; symdiff!(s, n); end; s) +symdiff!(s::PositiveIntSet, ns) = (for n in ns; symdiff!(s, n); end; s) """ symdiff!(s, n) The set `s` is destructively modified to toggle the inclusion of integer `n`. """ -function symdiff!(s::IntSet, n::Integer) +function symdiff!(s::PositiveIntSet, n::Integer) 0 <= n < typemax(Int) || _throw_intset_bounds_err() val = !(n in s) _setint!(s, n, val) s end -function symdiff!(s1::IntSet, s2::IntSet) +function symdiff!(s1::PositiveIntSet, s2::PositiveIntSet) _matched_map!(xor, s1.bits, s2.bits) s1 end -@inline function in(n::Integer, s::IntSet) +@inline function in(n::Integer, s::PositiveIntSet) if 1 <= n <= length(s.bits) @inbounds b = s.bits[n] else @@ -160,24 +160,24 @@ end end # Use the next-set index as the state to prevent looking it up again in done -start(s::IntSet) = next(s, 0)[2] -function next(s::IntSet, i) +start(s::PositiveIntSet) = next(s, 0)[2] +function next(s::PositiveIntSet, i) nextidx = i == typemax(Int) ? 0 : findnext(s.bits, i+1) (i, nextidx) end -done(s::IntSet, i) = i <= 0 +done(s::PositiveIntSet, i) = i <= 0 @noinline _throw_intset_notempty_error() = throw(ArgumentError("collection must be non-empty")) -function last(s::IntSet) +function last(s::PositiveIntSet) idx = findprev(s.bits, length(s.bits)) idx == 0 ? _throw_intset_notempty_error() : idx end -length(s::IntSet) = sum(s.bits) +length(s::PositiveIntSet) = sum(s.bits) -function show(io::IO, s::IntSet) - print(io, "IntSet([") +function show(io::IO, s::PositiveIntSet) + print(io, "PositiveIntSet([") first = true for n in s !first && print(io, ", ") @@ -187,7 +187,7 @@ function show(io::IO, s::IntSet) print(io, "])") end -function ==(s1::IntSet, s2::IntSet) +function ==(s1::PositiveIntSet, s2::PositiveIntSet) l1 = length(s1.bits) l2 = length(s2.bits) # If the lengths are the same, simply punt to bitarray comparison @@ -211,12 +211,12 @@ function ==(s1::IntSet, s2::IntSet) return true end -issubset(a::IntSet, b::IntSet) = isequal(a, intersect(a,b)) -<(a::IntSet, b::IntSet) = (a<=b) && !isequal(a,b) -<=(a::IntSet, b::IntSet) = issubset(a, b) +issubset(a::PositiveIntSet, b::PositiveIntSet) = isequal(a, intersect(a,b)) +<(a::PositiveIntSet, b::PositiveIntSet) = (a<=b) && !isequal(a,b) +<=(a::PositiveIntSet, b::PositiveIntSet) = issubset(a, b) const hashis_seed = UInt === UInt64 ? 0x88989f1fc7dea67d : 0xc7dea67d -function hash(s::IntSet, h::UInt) +function hash(s::PositiveIntSet, h::UInt) h ⊻= hashis_seed bc = s.bits.chunks i = length(bc) diff --git a/base/parallel/process_messages.jl b/base/parallel/process_messages.jl index e0c8cf5f0e7ac..f2f002aefc9b2 100644 --- a/base/parallel/process_messages.jl +++ b/base/parallel/process_messages.jl @@ -4,13 +4,13 @@ def_rv_channel() = Channel(1) type RemoteValue c::AbstractChannel - clientset::IntSet # Set of workerids that have a reference to this channel. + clientset::PositiveIntSet # Set of workerids that have a reference to this channel. # Keeping ids instead of a count aids in cleaning up upon # a worker exit. waitingfor::Int # processor we need to hear from to fill this, or 0 - RemoteValue(c) = new(c, IntSet(), 0) + RemoteValue(c) = new(c, PositiveIntSet(), 0) end wait(rv::RemoteValue) = wait(rv.c) diff --git a/base/precompile.jl b/base/precompile.jl index 86247eec17b9d..ca0f333829c38 100644 --- a/base/precompile.jl +++ b/base/precompile.jl @@ -198,7 +198,7 @@ precompile(Base.deleteat!, (Array{UInt8, 1}, Base.UnitRange{Int})) precompile(Base.done, (Array{Base.LineEdit.TextInterface, 1}, Int)) precompile(Base.done, (Dict{Any,Any}, Int)) precompile(Base.done, (Dict{Symbol,Any}, Int)) -precompile(Base.done, (IntSet, Int)) +precompile(Base.done, (PositiveIntSet, Int)) precompile(Base.done, (UnitRange{Int},Int)) precompile(Base.endof, (Array{Any,1},)) precompile(Base.enq_work, (Task,)) @@ -276,7 +276,7 @@ precompile(Base.min, (Int32, Int32)) precompile(Base.next, (Array{Base.LineEdit.TextInterface, 1}, Int)) precompile(Base.next, (Dict{Any,Any}, Int)) precompile(Base.next, (Dict{Symbol,Any},Int)) -precompile(Base.next, (IntSet, Int)) +precompile(Base.next, (PositiveIntSet, Int)) precompile(Base.next, (UnitRange{Int},Int)) precompile(Base.nextind, (String, Int)) precompile(Base.normpath, (String, String)) diff --git a/doc/src/stdlib/collections.md b/doc/src/stdlib/collections.md index 29d8c38f3b1a8..5d50c39a11c00 100644 --- a/doc/src/stdlib/collections.md +++ b/doc/src/stdlib/collections.md @@ -40,7 +40,7 @@ Fully implemented by: * `Tuple` * `Number` * `AbstractArray` - * [`IntSet`](@ref) + * [`PositiveIntSet`](@ref) * [`ObjectIdDict`](@ref) * [`Dict`](@ref) * [`WeakKeyDict`](@ref) @@ -64,7 +64,7 @@ Fully implemented by: * `Tuple` * `Number` * `AbstractArray` - * [`IntSet`](@ref) + * [`PositiveIntSet`](@ref) * [`ObjectIdDict`](@ref) * [`Dict`](@ref) * [`WeakKeyDict`](@ref) @@ -210,7 +210,7 @@ Fully implemented by: Partially implemented by: - * [`IntSet`](@ref) + * [`PositiveIntSet`](@ref) * [`Set`](@ref) * [`EnvHash`](@ref Base.EnvHash) * [`Array`](@ref) @@ -220,23 +220,23 @@ Partially implemented by: ```@docs Base.Set -Base.IntSet +Base.PositiveIntSet Base.union Base.union! Base.intersect Base.setdiff Base.setdiff! Base.symdiff -Base.symdiff!(::IntSet, ::Integer) -Base.symdiff!(::IntSet, ::Any) -Base.symdiff!(::IntSet, ::IntSet) +Base.symdiff!(::PositiveIntSet, ::Integer) +Base.symdiff!(::PositiveIntSet, ::Any) +Base.symdiff!(::PositiveIntSet, ::PositiveIntSet) Base.intersect! Base.issubset ``` Fully implemented by: - * [`IntSet`](@ref) + * [`PositiveIntSet`](@ref) * [`Set`](@ref) Partially implemented by: diff --git a/test/intset.jl b/test/intset.jl index 559d6a7e52459..a0849290500dc 100644 --- a/test/intset.jl +++ b/test/intset.jl @@ -1,29 +1,29 @@ # This file is a part of Julia. License is MIT: http://julialang.org/license -# Test functionality of IntSet +# Test functionality of PositiveIntSet @testset "Construction, collect" begin data_in = (1,5,100) - s = IntSet(data_in) + s = PositiveIntSet(data_in) data_out = collect(s) @test all(map(d->in(d,data_out), data_in)) @test length(data_out) === length(data_in) end @testset "eltype, similar" begin - @test eltype(IntSet()) === Int - @test eltype(IntSet) === Int - @test isequal(similar(IntSet([1,2,3])), IntSet()) + @test eltype(PositiveIntSet()) === Int + @test eltype(PositiveIntSet) === Int + @test isequal(similar(PositiveIntSet([1,2,3])), PositiveIntSet()) end @testset "show" begin - @test sprint(show, IntSet()) == "IntSet([])" - @test sprint(show, IntSet([1,2,3])) == "IntSet([1, 2, 3])" - show(IOBuffer(), IntSet()) + @test sprint(show, PositiveIntSet()) == "PositiveIntSet([])" + @test sprint(show, PositiveIntSet([1,2,3])) == "PositiveIntSet([1, 2, 3])" + show(IOBuffer(), PositiveIntSet()) end @testset "in, hashing" begin - s = IntSet([1,2,10,20,200,300,1000,10000,10002]) + s = PositiveIntSet([1,2,10,20,200,300,1000,10000,10002]) @test last(s) === 10002 @test first(s) === 1 @test length(s) === 9 @@ -39,8 +39,8 @@ end @test in(10000,s) @test in(10000.0,s) @test !in(10002.0,s) - @test_throws ArgumentError first(IntSet()) - @test_throws ArgumentError last(IntSet()) + @test_throws ArgumentError first(PositiveIntSet()) + @test_throws ArgumentError last(PositiveIntSet()) t = copy(s) sizehint!(t, 20000) #check that hash does not depend on size of internal storage @test hash(s) === hash(t) @@ -51,24 +51,24 @@ end @test pop!(t, 20000) === 20000 @test hash(s) === hash(t) # Ensure empty chunks don't affect hash - @test hash(IntSet([1])) != hash(IntSet([17])) - @test hash(IntSet([1])) != hash(IntSet([33])) - @test hash(IntSet([1])) != hash(IntSet([65])) - @test hash(IntSet([1])) != hash(IntSet([129])) + @test hash(PositiveIntSet([1])) != hash(PositiveIntSet([17])) + @test hash(PositiveIntSet([1])) != hash(PositiveIntSet([33])) + @test hash(PositiveIntSet([1])) != hash(PositiveIntSet([65])) + @test hash(PositiveIntSet([1])) != hash(PositiveIntSet([129])) # issue #7851 - @test_throws ArgumentError IntSet(-1) - @test !(-1 in IntSet(1:10)) + @test_throws ArgumentError PositiveIntSet(-1) + @test !(-1 in PositiveIntSet(1:10)) end # # issue #8570 # This requires 2^29 bytes of storage, which is too much for a simple test -# s = IntSet(typemax(Int32)) +# s = PositiveIntSet(typemax(Int32)) # @test length(s) === 1 # for b in s; b; end @testset "union!, symdiff!" begin - i = IntSet([1, 2, 3]) + i = PositiveIntSet([1, 2, 3]) union!(i, [1, 2]) @test length(i) === 3 union!(i, [3, 4, 5]) @@ -80,16 +80,16 @@ end @test length(i) === 0 @test_throws ArgumentError symdiff!(i, -3) - @test symdiff!(i, 3) == IntSet([3]) - @test symdiff!(i, 257) == IntSet([3, 257]) - @test symdiff!(i, [3, 6]) == IntSet([6, 257]) + @test symdiff!(i, 3) == PositiveIntSet([3]) + @test symdiff!(i, 257) == PositiveIntSet([3, 257]) + @test symdiff!(i, [3, 6]) == PositiveIntSet([6, 257]) - i = IntSet(1:6) - @test symdiff!(i, IntSet([6, 513])) == IntSet([1:5; 513]) + i = PositiveIntSet(1:6) + @test symdiff!(i, PositiveIntSet([6, 513])) == PositiveIntSet([1:5; 513]) end @testset "copy, copy!, similar" begin - s1 = IntSet([1,2,3]) + s1 = PositiveIntSet([1,2,3]) s2 = similar(s1) copy!(s2, s1) s3 = copy(s2) @@ -98,43 +98,43 @@ end end @testset "push!, union" begin - i = IntSet([1, 2, 3]) + i = PositiveIntSet([1, 2, 3]) j = union(i) @test j == i @test !(j === i) - j = IntSet([4, 5, 6]) - @test union(i, j) == IntSet(1:6) + j = PositiveIntSet([4, 5, 6]) + @test union(i, j) == PositiveIntSet(1:6) - k = IntSet([7, 8, 9]) - @test union(i, j, k) == IntSet(1:9) - i = IntSet([1, 2, 3]) + k = PositiveIntSet([7, 8, 9]) + @test union(i, j, k) == PositiveIntSet(1:9) + i = PositiveIntSet([1, 2, 3]) j = union(i) @test j == i @test !(j === i) - j = IntSet([4, 5, 6]) - @test union(i, j) == IntSet(1:6) + j = PositiveIntSet([4, 5, 6]) + @test union(i, j) == PositiveIntSet(1:6) - k = IntSet([7, 8, 9]) - @test union(i, j, k) == IntSet(1:9) + k = PositiveIntSet([7, 8, 9]) + @test union(i, j, k) == PositiveIntSet(1:9) - s1 = IntSet() + s1 = PositiveIntSet() @test_throws ArgumentError push!(s1, -1) push!(s1, 1, 10, 100, 1000) @test collect(s1) == [1, 10, 100, 1000] push!(s1, 606) @test collect(s1) == [1, 10, 100, 606, 1000] - s2 = IntSet() + s2 = PositiveIntSet() @test s2 === union!(s2, s1) - s3 = IntSet([1, 10, 100]) + s3 = PositiveIntSet([1, 10, 100]) union!(s3, [1, 606, 1000]) - s4 = union(IntSet([1, 100, 1000]), IntSet([10, 100, 606])) + s4 = union(PositiveIntSet([1, 100, 1000]), PositiveIntSet([10, 100, 606])) @test s1 == s2 == s3 == s4 end @testset "pop!, delete!" begin - s = IntSet(1:2:10) + s = PositiveIntSet(1:2:10) @test pop!(s, 1) === 1 @test !(1 in s) @test_throws KeyError pop!(s, 1) @@ -157,60 +157,60 @@ end end @testset "intersect" begin - i = IntSet([1, 2, 3]) - j = IntSet([4, 5, 6]) + i = PositiveIntSet([1, 2, 3]) + j = PositiveIntSet([4, 5, 6]) @test intersect(i) == i @test !(intersect(i) === i) - @test intersect(i, j) == IntSet([]) + @test intersect(i, j) == PositiveIntSet([]) push!(j, 257) - @test intersect(i, j) == IntSet([]) + @test intersect(i, j) == PositiveIntSet([]) push!(j, 2, 3, 17) - @test intersect(i, j) == IntSet([2, 3]) - k = IntSet([1, 2, 3, 4, 5, 6, 7]) - @test intersect(i, j, k) == IntSet([2, 3]) - - @test isempty(intersect(IntSet())) - @test isempty(intersect(IntSet(1:10), IntSet())) - @test isempty(intersect(IntSet(), IntSet(1:10))) - - @test intersect(IntSet([1,2,3])) == IntSet([1,2,3]) - @test intersect(IntSet(1:7), IntSet(3:10)) == - intersect(IntSet(3:10), IntSet(1:7)) == IntSet(3:7) - @test intersect(IntSet(1:10), IntSet(1:4), 1:5, [2,3,10]) == [2,3] + @test intersect(i, j) == PositiveIntSet([2, 3]) + k = PositiveIntSet([1, 2, 3, 4, 5, 6, 7]) + @test intersect(i, j, k) == PositiveIntSet([2, 3]) + + @test isempty(intersect(PositiveIntSet())) + @test isempty(intersect(PositiveIntSet(1:10), PositiveIntSet())) + @test isempty(intersect(PositiveIntSet(), PositiveIntSet(1:10))) + + @test intersect(PositiveIntSet([1,2,3])) == PositiveIntSet([1,2,3]) + @test intersect(PositiveIntSet(1:7), PositiveIntSet(3:10)) == + intersect(PositiveIntSet(3:10), PositiveIntSet(1:7)) == PositiveIntSet(3:7) + @test intersect(PositiveIntSet(1:10), PositiveIntSet(1:4), 1:5, [2,3,10]) == [2,3] end @testset "setdiff, symdiff" begin - @test setdiff(IntSet([1, 2, 3, 4]), IntSet([2, 4, 5, 6])) == IntSet([1, 3]) - @test symdiff(IntSet([1, 2, 3, 4]), IntSet([2, 4, 5, 6])) == IntSet([1, 3, 5, 6]) + @test setdiff(PositiveIntSet([1, 2, 3, 4]), PositiveIntSet([2, 4, 5, 6])) == PositiveIntSet([1, 3]) + @test symdiff(PositiveIntSet([1, 2, 3, 4]), PositiveIntSet([2, 4, 5, 6])) == PositiveIntSet([1, 3, 5, 6]) - s2 = IntSet([1, 2, 3, 4]) - setdiff!(s2, IntSet([2, 4, 5, 6])) - @test s2 == IntSet([1, 3]) + s2 = PositiveIntSet([1, 2, 3, 4]) + setdiff!(s2, PositiveIntSet([2, 4, 5, 6])) + @test s2 == PositiveIntSet([1, 3]) - s1 = IntSet(1:100) - setdiff!(s1, IntSet(1:2:100)) - s2 = setdiff(IntSet(1:100), IntSet(1:2:100)) - @test s1 == s2 == IntSet(2:2:100) + s1 = PositiveIntSet(1:100) + setdiff!(s1, PositiveIntSet(1:2:100)) + s2 = setdiff(PositiveIntSet(1:100), PositiveIntSet(1:2:100)) + @test s1 == s2 == PositiveIntSet(2:2:100) @test collect(s1) == collect(2:2:100) - @test symdiff(IntSet([1, 2, 3, 4]), IntSet([2, 4, 5, 6])) == - symdiff(IntSet([2, 4, 5, 6]), IntSet([1, 2, 3, 4])) == - symdiff(IntSet([1, 2, 3, 4]), [2, 4, 5, 6]) == - symdiff(IntSet([2, 4, 5, 6]), [1, 2, 3, 4]) == IntSet([1, 3, 5, 6]) + @test symdiff(PositiveIntSet([1, 2, 3, 4]), PositiveIntSet([2, 4, 5, 6])) == + symdiff(PositiveIntSet([2, 4, 5, 6]), PositiveIntSet([1, 2, 3, 4])) == + symdiff(PositiveIntSet([1, 2, 3, 4]), [2, 4, 5, 6]) == + symdiff(PositiveIntSet([2, 4, 5, 6]), [1, 2, 3, 4]) == PositiveIntSet([1, 3, 5, 6]) end @testset "subsets, equality" begin - i = IntSet([1, 2, 3]) - k = IntSet([4, 5]) + i = PositiveIntSet([1, 2, 3]) + k = PositiveIntSet([4, 5]) copy!(k, i) @test k == i @test !(k === i) copy!(k, k) @test k == i - i = IntSet([1, 2, 3]) - j = IntSet([1, 2, 4]) + i = PositiveIntSet([1, 2, 3]) + j = PositiveIntSet([1, 2, 4]) @test i != j push!(j, 257) @@ -218,28 +218,28 @@ end @test i != j @test j != i - @test issubset(IntSet([1, 2, 4]), IntSet(1:10)) - @test issubset(IntSet([]), IntSet([])) - @test IntSet([1, 2, 4]) < IntSet(1:10) - @test !(IntSet([]) < IntSet([])) - @test IntSet([1, 2, 4]) <= IntSet(1:10) - @test IntSet([1, 2, 4]) <= IntSet([1, 2, 4]) - @test IntSet([]) <= IntSet([]) + @test issubset(PositiveIntSet([1, 2, 4]), PositiveIntSet(1:10)) + @test issubset(PositiveIntSet([]), PositiveIntSet([])) + @test PositiveIntSet([1, 2, 4]) < PositiveIntSet(1:10) + @test !(PositiveIntSet([]) < PositiveIntSet([])) + @test PositiveIntSet([1, 2, 4]) <= PositiveIntSet(1:10) + @test PositiveIntSet([1, 2, 4]) <= PositiveIntSet([1, 2, 4]) + @test PositiveIntSet([]) <= PositiveIntSet([]) - @test IntSet(2:2:10) < IntSet(1:10) - @test !(IntSet(2:2:10) < IntSet(2:2:10)) - @test IntSet(2:2:10) <= IntSet(2:10) - @test IntSet(2:2:10) <= IntSet(2:2:10) + @test PositiveIntSet(2:2:10) < PositiveIntSet(1:10) + @test !(PositiveIntSet(2:2:10) < PositiveIntSet(2:2:10)) + @test PositiveIntSet(2:2:10) <= PositiveIntSet(2:10) + @test PositiveIntSet(2:2:10) <= PositiveIntSet(2:2:10) # == with last-bit set (groups.google.com/forum/#!topic/julia-users/vZNjiIEG_sY) - s = IntSet(255) + s = PositiveIntSet(255) @test s == s end @testset "setlike" begin - p = IntSet([1,2,5,6]) + p = PositiveIntSet([1,2,5,6]) resize!(p.bits, 6) - q = IntSet([1,3,5,7]) + q = PositiveIntSet([1,3,5,7]) resize!(q.bits, 8) a = Set(p) b = Set(q) @@ -252,7 +252,7 @@ end end @testset "misc" begin - s = IntSet() + s = PositiveIntSet() push!(s, 1, 2, 100) @test !(0 in s) @test 1 in s @@ -263,15 +263,15 @@ end @test !(1000 in s) @test first(s) === 1 @test last(s) === 100 - @test s == IntSet([1, 2, 100]) + @test s == PositiveIntSet([1, 2, 100]) push!(s, 1000) @test [i for i in s] == [1, 2, 100, 1000] @test pop!(s) === 1000 - @test s == IntSet([1, 2, 100]) - @test hash(s) === hash(IntSet([1, 2, 100])) + @test s == PositiveIntSet([1, 2, 100]) + @test hash(s) === hash(PositiveIntSet([1, 2, 100])) b = 1:1000 - s = IntSet(b) + s = PositiveIntSet(b) @test collect(s) == collect(b) @test length(s) === length(b) @test pop!(s, 100) === 100