Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename IntSet to PositiveIntSet #20512

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions base/dates/query.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions base/docs/helpdb/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export
Hermitian,
UniformScaling,
InsertionSort,
IntSet,
PositiveIntSet,
IOBuffer,
IOStream,
LinSpace,
Expand Down
12 changes: 6 additions & 6 deletions base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@ type InferenceState
# return type
bestguess #::Type
# current active instruction pointers
ip::IntSet
ip::PositiveIntSet
pc´´::Int
nstmts::Int
# current exception handler info
cur_hand #::Tuple{LineNum, Tuple{LineNum, ...}}
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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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)
Expand Down
110 changes: 55 additions & 55 deletions base/intset.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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, ", ")
Expand All @@ -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
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions base/parallel/process_messages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions base/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,))
Expand Down Expand Up @@ -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))
Expand Down
Loading