Skip to content

Commit 800fc2e

Browse files
committed
Rename IntSet to PositiveIntSet
Following #20456 this is a better and more accurate name.
1 parent 12dd7a5 commit 800fc2e

File tree

10 files changed

+174
-172
lines changed

10 files changed

+174
-172
lines changed

base/dates/query.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ end
157157

158158
# Total number of a day of week in the month
159159
# e.g. are there 4 or 5 Mondays in this month?
160-
const TWENTYNINE = IntSet([1, 8, 15, 22, 29])
161-
const THIRTY = IntSet([1, 2, 8, 9, 15, 16, 22, 23, 29, 30])
162-
const THIRTYONE = IntSet([1, 2, 3, 8, 9, 10, 15, 16, 17, 22, 23, 24, 29, 30, 31])
160+
const TWENTYNINE = PositiveIntSet([1, 8, 15, 22, 29])
161+
const THIRTY = PositiveIntSet([1, 2, 8, 9, 15, 16, 22, 23, 29, 30])
162+
const THIRTYONE = PositiveIntSet([1, 2, 3, 8, 9, 10, 15, 16, 17, 22, 23, 24, 29, 30, 31])
163163

164164
"""
165165
daysofweekinmonth(dt::TimeType) -> Int

base/deprecated.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,8 @@ function (::Type{Matrix})()
12211221
return Matrix(0, 0)
12221222
end
12231223

1224+
@deprecate_binding IntSet PositiveIntSet
1225+
12241226
for name in ("alnum", "alpha", "cntrl", "digit", "number", "graph",
12251227
"lower", "print", "punct", "space", "upper", "xdigit")
12261228
f = Symbol("is",name)

base/docs/helpdb/Base.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,14 +1450,14 @@ The arguments to a function or constructor are outside the valid domain.
14501450
DomainError
14511451

14521452
"""
1453-
IntSet([itr])
1453+
PositiveIntSet([itr])
14541454
14551455
Construct a sorted set of positive `Int`s generated by the given iterable object, or an
14561456
empty set. Implemented as a bit string, and therefore designed for dense integer sets. Only
14571457
`Int`s greater than 0 can be stored. If the set will be sparse (for example holding a few
14581458
very large integers), use [`Set`](@ref) instead.
14591459
"""
1460-
IntSet
1460+
PositiveIntSet
14611461

14621462
"""
14631463
Task(func)
@@ -2379,7 +2379,7 @@ widen
23792379
Set([itr])
23802380
23812381
Construct a [`Set`](@ref) of the values generated by the given iterable object, or an
2382-
empty set. Should be used instead of [`IntSet`](@ref) for sparse integer sets, or
2382+
empty set. Should be used instead of [`PositiveIntSet`](@ref) for sparse integer sets, or
23832383
for sets of arbitrary objects.
23842384
"""
23852385
Set

base/exports.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export
6767
Hermitian,
6868
UniformScaling,
6969
InsertionSort,
70-
IntSet,
70+
PositiveIntSet,
7171
IOBuffer,
7272
IOStream,
7373
LinSpace,

base/inference.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,15 @@ type InferenceState
115115
# return type
116116
bestguess #::Type
117117
# current active instruction pointers
118-
ip::IntSet
118+
ip::PositiveIntSet
119119
pc´´::Int
120120
nstmts::Int
121121
# current exception handler info
122122
cur_hand #::Tuple{LineNum, Tuple{LineNum, ...}}
123123
handler_at::Vector{Any}
124124
n_handlers::Int
125125
# ssavalue sparsity and restart info
126-
ssavalue_uses::Vector{IntSet}
126+
ssavalue_uses::Vector{PositiveIntSet}
127127
ssavalue_init::Vector{Any}
128128
# call-graph edges connecting from a caller to a callee (and back)
129129
# 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
232232
handler_at = Any[ () for i=1:n ]
233233
n_handlers = 0
234234

235-
W = IntSet()
235+
W = PositiveIntSet()
236236
push!(W, 1) #initial pc to visit
237237

238238
if !toplevel
@@ -2170,7 +2170,7 @@ end
21702170
genlabel(sv) = LabelNode(sv.label_counter += 1)
21712171

21722172
function find_ssavalue_uses(body)
2173-
uses = IntSet[]
2173+
uses = PositiveIntSet[]
21742174
for line = 1:length(body)
21752175
find_ssavalue_uses(body[line], uses, line)
21762176
end
@@ -2180,7 +2180,7 @@ function find_ssavalue_uses(e::ANY, uses, line)
21802180
if isa(e,SSAValue)
21812181
id = (e::SSAValue).id + 1
21822182
while length(uses) < id
2183-
push!(uses, IntSet())
2183+
push!(uses, PositiveIntSet())
21842184
end
21852185
push!(uses[id], line)
21862186
elseif isa(e,Expr)
@@ -2191,7 +2191,7 @@ function find_ssavalue_uses(e::ANY, uses, line)
21912191
if isa(b.args[1],SSAValue)
21922192
id = (b.args[1]::SSAValue).id + 1
21932193
while length(uses) < id
2194-
push!(uses, IntSet())
2194+
push!(uses, PositiveIntSet())
21952195
end
21962196
end
21972197
find_ssavalue_uses(b.args[2], uses, line)

base/intset.jl

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
# This file is a part of Julia. License is MIT: http://julialang.org/license
22

3-
immutable IntSet <: AbstractSet{Int}
3+
immutable PositiveIntSet <: AbstractSet{Int}
44
bits::BitVector
5-
IntSet() = new(falses(256))
5+
PositiveIntSet() = new(falses(256))
66
end
7-
IntSet(itr) = union!(IntSet(), itr)
7+
PositiveIntSet(itr) = union!(PositiveIntSet(), itr)
88

9-
eltype(::Type{IntSet}) = Int
10-
similar(s::IntSet) = IntSet()
11-
copy(s1::IntSet) = copy!(IntSet(), s1)
12-
function copy!(dest::IntSet, src::IntSet)
9+
eltype(::Type{PositiveIntSet}) = Int
10+
similar(s::PositiveIntSet) = PositiveIntSet()
11+
copy(s1::PositiveIntSet) = copy!(PositiveIntSet(), s1)
12+
function copy!(dest::PositiveIntSet, src::PositiveIntSet)
1313
resize!(dest.bits, length(src.bits))
1414
copy!(dest.bits, src.bits)
1515
dest
1616
end
17-
eltype(s::IntSet) = Int
18-
sizehint!(s::IntSet, n::Integer) = (_resize0!(s.bits, max(n, length(s.bits))); s)
17+
eltype(s::PositiveIntSet) = Int
18+
sizehint!(s::PositiveIntSet, n::Integer) = (_resize0!(s.bits, max(n, length(s.bits))); s)
1919

2020
# An internal function for setting the inclusion bit for a given integer n >= 0
21-
@inline function _setint!(s::IntSet, idx::Integer, b::Bool)
21+
@inline function _setint!(s::PositiveIntSet, idx::Integer, b::Bool)
2222
if idx > length(s.bits)
2323
b || return s # setting a bit to zero outside the set's bits is a no-op
2424
newlen = idx + idx>>1 # This operation may overflow; we want saturation
@@ -52,7 +52,7 @@ function _matched_map!(f, b1::BitArray, b2::BitArray)
5252
resize!(b1, l2)
5353
map!(f, b1, b1, b2)
5454
else
55-
# We transiently extend b2 — as IntSet internal storage this is unobservable
55+
# We transiently extend b2 — as PositiveIntSet internal storage this is unobservable
5656
_resize0!(b2, l1)
5757
map!(f, b1, b1, b2)
5858
resize!(b2, l2)
@@ -61,96 +61,96 @@ function _matched_map!(f, b1::BitArray, b2::BitArray)
6161
b1
6262
end
6363

64-
@noinline _throw_intset_bounds_err() = throw(ArgumentError("elements of IntSet must be between 1 and typemax(Int)"))
64+
@noinline _throw_intset_bounds_err() = throw(ArgumentError("elements of PositiveIntSet must be between 1 and typemax(Int)"))
6565
@noinline _throw_keyerror(n) = throw(KeyError(n))
6666

67-
@inline function push!(s::IntSet, n::Integer)
67+
@inline function push!(s::PositiveIntSet, n::Integer)
6868
0 < n <= typemax(Int) || _throw_intset_bounds_err()
6969
_setint!(s, n, true)
7070
end
71-
push!(s::IntSet, ns::Integer...) = (for n in ns; push!(s, n); end; s)
71+
push!(s::PositiveIntSet, ns::Integer...) = (for n in ns; push!(s, n); end; s)
7272

73-
@inline function pop!(s::IntSet)
73+
@inline function pop!(s::PositiveIntSet)
7474
pop!(s, last(s))
7575
end
76-
@inline function pop!(s::IntSet, n::Integer)
76+
@inline function pop!(s::PositiveIntSet, n::Integer)
7777
n in s ? (_delete!(s, n); n) : _throw_keyerror(n)
7878
end
79-
@inline function pop!(s::IntSet, n::Integer, default)
79+
@inline function pop!(s::PositiveIntSet, n::Integer, default)
8080
n in s ? (_delete!(s, n); n) : default
8181
end
82-
@inline _delete!(s::IntSet, n::Integer) = _setint!(s, n, false)
83-
@inline delete!(s::IntSet, n::Integer) = n < 0 ? s : _delete!(s, n)
84-
shift!(s::IntSet) = pop!(s, first(s))
82+
@inline _delete!(s::PositiveIntSet, n::Integer) = _setint!(s, n, false)
83+
@inline delete!(s::PositiveIntSet, n::Integer) = n < 0 ? s : _delete!(s, n)
84+
shift!(s::PositiveIntSet) = pop!(s, first(s))
8585

86-
empty!(s::IntSet) = (fill!(s.bits, false); s)
87-
isempty(s::IntSet) = !any(s.bits)
86+
empty!(s::PositiveIntSet) = (fill!(s.bits, false); s)
87+
isempty(s::PositiveIntSet) = !any(s.bits)
8888

8989
# Mathematical set functions: union!, intersect!, setdiff!, symdiff!
9090

91-
union(s::IntSet) = copy(s)
92-
union(s1::IntSet, s2::IntSet) = union!(copy(s1), s2)
93-
union(s1::IntSet, ss::IntSet...) = union(s1, union(ss...))
94-
union(s::IntSet, ns) = union!(copy(s), ns)
95-
union!(s::IntSet, ns) = (for n in ns; push!(s, n); end; s)
96-
function union!(s1::IntSet, s2::IntSet)
91+
union(s::PositiveIntSet) = copy(s)
92+
union(s1::PositiveIntSet, s2::PositiveIntSet) = union!(copy(s1), s2)
93+
union(s1::PositiveIntSet, ss::PositiveIntSet...) = union(s1, union(ss...))
94+
union(s::PositiveIntSet, ns) = union!(copy(s), ns)
95+
union!(s::PositiveIntSet, ns) = (for n in ns; push!(s, n); end; s)
96+
function union!(s1::PositiveIntSet, s2::PositiveIntSet)
9797
_matched_map!(|, s1.bits, s2.bits)
9898
s1
9999
end
100100

101-
intersect(s1::IntSet) = copy(s1)
102-
intersect(s1::IntSet, ss::IntSet...) = intersect(s1, intersect(ss...))
103-
function intersect(s1::IntSet, ns)
104-
s = IntSet()
101+
intersect(s1::PositiveIntSet) = copy(s1)
102+
intersect(s1::PositiveIntSet, ss::PositiveIntSet...) = intersect(s1, intersect(ss...))
103+
function intersect(s1::PositiveIntSet, ns)
104+
s = PositiveIntSet()
105105
for n in ns
106106
n in s1 && push!(s, n)
107107
end
108108
s
109109
end
110-
intersect(s1::IntSet, s2::IntSet) =
110+
intersect(s1::PositiveIntSet, s2::PositiveIntSet) =
111111
(length(s1.bits) >= length(s2.bits) ? intersect!(copy(s1), s2) : intersect!(copy(s2), s1))
112112
"""
113-
intersect!(s1::IntSet, s2::IntSet)
113+
intersect!(s1::PositiveIntSet, s2::PositiveIntSet)
114114
115115
Intersects sets `s1` and `s2` and overwrites the set `s1` with the result. If needed, `s1`
116116
will be expanded to the size of `s2`.
117117
"""
118-
function intersect!(s1::IntSet, s2::IntSet)
118+
function intersect!(s1::PositiveIntSet, s2::PositiveIntSet)
119119
_matched_map!(&, s1.bits, s2.bits)
120120
s1
121121
end
122122

123-
setdiff(s::IntSet, ns) = setdiff!(copy(s), ns)
124-
setdiff!(s::IntSet, ns) = (for n in ns; _delete!(s, n); end; s)
125-
function setdiff!(s1::IntSet, s2::IntSet)
123+
setdiff(s::PositiveIntSet, ns) = setdiff!(copy(s), ns)
124+
setdiff!(s::PositiveIntSet, ns) = (for n in ns; _delete!(s, n); end; s)
125+
function setdiff!(s1::PositiveIntSet, s2::PositiveIntSet)
126126
_matched_map!(>, s1.bits, s2.bits)
127127
s1
128128
end
129129

130-
symdiff(s::IntSet, ns) = symdiff!(copy(s), ns)
130+
symdiff(s::PositiveIntSet, ns) = symdiff!(copy(s), ns)
131131
"""
132132
symdiff!(s, itr)
133133
134134
For each element in `itr`, destructively toggle its inclusion in set `s`.
135135
"""
136-
symdiff!(s::IntSet, ns) = (for n in ns; symdiff!(s, n); end; s)
136+
symdiff!(s::PositiveIntSet, ns) = (for n in ns; symdiff!(s, n); end; s)
137137
"""
138138
symdiff!(s, n)
139139
140140
The set `s` is destructively modified to toggle the inclusion of integer `n`.
141141
"""
142-
function symdiff!(s::IntSet, n::Integer)
142+
function symdiff!(s::PositiveIntSet, n::Integer)
143143
0 <= n < typemax(Int) || _throw_intset_bounds_err()
144144
val = !(n in s)
145145
_setint!(s, n, val)
146146
s
147147
end
148-
function symdiff!(s1::IntSet, s2::IntSet)
148+
function symdiff!(s1::PositiveIntSet, s2::PositiveIntSet)
149149
_matched_map!(xor, s1.bits, s2.bits)
150150
s1
151151
end
152152

153-
@inline function in(n::Integer, s::IntSet)
153+
@inline function in(n::Integer, s::PositiveIntSet)
154154
if 1 <= n <= length(s.bits)
155155
@inbounds b = s.bits[n]
156156
else
@@ -160,24 +160,24 @@ end
160160
end
161161

162162
# Use the next-set index as the state to prevent looking it up again in done
163-
start(s::IntSet) = next(s, 0)[2]
164-
function next(s::IntSet, i)
163+
start(s::PositiveIntSet) = next(s, 0)[2]
164+
function next(s::PositiveIntSet, i)
165165
nextidx = i == typemax(Int) ? 0 : findnext(s.bits, i+1)
166166
(i, nextidx)
167167
end
168-
done(s::IntSet, i) = i <= 0
168+
done(s::PositiveIntSet, i) = i <= 0
169169

170170

171171
@noinline _throw_intset_notempty_error() = throw(ArgumentError("collection must be non-empty"))
172-
function last(s::IntSet)
172+
function last(s::PositiveIntSet)
173173
idx = findprev(s.bits, length(s.bits))
174174
idx == 0 ? _throw_intset_notempty_error() : idx
175175
end
176176

177-
length(s::IntSet) = sum(s.bits)
177+
length(s::PositiveIntSet) = sum(s.bits)
178178

179-
function show(io::IO, s::IntSet)
180-
print(io, "IntSet([")
179+
function show(io::IO, s::PositiveIntSet)
180+
print(io, "PositiveIntSet([")
181181
first = true
182182
for n in s
183183
!first && print(io, ", ")
@@ -187,7 +187,7 @@ function show(io::IO, s::IntSet)
187187
print(io, "])")
188188
end
189189

190-
function ==(s1::IntSet, s2::IntSet)
190+
function ==(s1::PositiveIntSet, s2::PositiveIntSet)
191191
l1 = length(s1.bits)
192192
l2 = length(s2.bits)
193193
# If the lengths are the same, simply punt to bitarray comparison
@@ -211,12 +211,12 @@ function ==(s1::IntSet, s2::IntSet)
211211
return true
212212
end
213213

214-
issubset(a::IntSet, b::IntSet) = isequal(a, intersect(a,b))
215-
<(a::IntSet, b::IntSet) = (a<=b) && !isequal(a,b)
216-
<=(a::IntSet, b::IntSet) = issubset(a, b)
214+
issubset(a::PositiveIntSet, b::PositiveIntSet) = isequal(a, intersect(a,b))
215+
<(a::PositiveIntSet, b::PositiveIntSet) = (a<=b) && !isequal(a,b)
216+
<=(a::PositiveIntSet, b::PositiveIntSet) = issubset(a, b)
217217

218218
const hashis_seed = UInt === UInt64 ? 0x88989f1fc7dea67d : 0xc7dea67d
219-
function hash(s::IntSet, h::UInt)
219+
function hash(s::PositiveIntSet, h::UInt)
220220
h ⊻= hashis_seed
221221
bc = s.bits.chunks
222222
i = length(bc)

base/parallel/process_messages.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
def_rv_channel() = Channel(1)
55
type RemoteValue
66
c::AbstractChannel
7-
clientset::IntSet # Set of workerids that have a reference to this channel.
7+
clientset::PositiveIntSet # Set of workerids that have a reference to this channel.
88
# Keeping ids instead of a count aids in cleaning up upon
99
# a worker exit.
1010

1111
waitingfor::Int # processor we need to hear from to fill this, or 0
1212

13-
RemoteValue(c) = new(c, IntSet(), 0)
13+
RemoteValue(c) = new(c, PositiveIntSet(), 0)
1414
end
1515

1616
wait(rv::RemoteValue) = wait(rv.c)

base/precompile.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ precompile(Base.deleteat!, (Array{UInt8, 1}, Base.UnitRange{Int}))
198198
precompile(Base.done, (Array{Base.LineEdit.TextInterface, 1}, Int))
199199
precompile(Base.done, (Dict{Any,Any}, Int))
200200
precompile(Base.done, (Dict{Symbol,Any}, Int))
201-
precompile(Base.done, (IntSet, Int))
201+
precompile(Base.done, (PositiveIntSet, Int))
202202
precompile(Base.done, (UnitRange{Int},Int))
203203
precompile(Base.endof, (Array{Any,1},))
204204
precompile(Base.enq_work, (Task,))
@@ -276,7 +276,7 @@ precompile(Base.min, (Int32, Int32))
276276
precompile(Base.next, (Array{Base.LineEdit.TextInterface, 1}, Int))
277277
precompile(Base.next, (Dict{Any,Any}, Int))
278278
precompile(Base.next, (Dict{Symbol,Any},Int))
279-
precompile(Base.next, (IntSet, Int))
279+
precompile(Base.next, (PositiveIntSet, Int))
280280
precompile(Base.next, (UnitRange{Int},Int))
281281
precompile(Base.nextind, (String, Int))
282282
precompile(Base.normpath, (String, String))

0 commit comments

Comments
 (0)