Skip to content

Commit 7ee7173

Browse files
committedAug 29, 2013
replace contains(x,y) with in(y,x). closes #4153
also add contains(String,String) to test for substrings
1 parent 3f73066 commit 7ee7173

33 files changed

+168
-161
lines changed
 

‎base/abstractarray.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ vec(a::AbstractVector) = a
157157
function squeeze(A::AbstractArray, dims)
158158
d = ()
159159
for i in 1:ndims(A)
160-
if contains(dims,i)
160+
if in(i,dims)
161161
if size(A,i) != 1
162162
error("squeezed dims must all be size 1")
163163
end
@@ -1397,12 +1397,12 @@ function nnz{T}(a::AbstractArray{T})
13971397
end
13981398

13991399
# for reductions that expand 0 dims to 1
1400-
reduced_dims(A, region) = ntuple(ndims(A), i->(contains(region, i) ? 1 :
1400+
reduced_dims(A, region) = ntuple(ndims(A), i->(in(i, region) ? 1 :
14011401
size(A,i)))
14021402

14031403
# keep 0 dims in place
14041404
reduced_dims0(A, region) = ntuple(ndims(A), i->(size(A,i)==0 ? 0 :
1405-
contains(region, i) ? 1 :
1405+
in(i, region) ? 1 :
14061406
size(A,i)))
14071407

14081408
reducedim(f::Function, A, region, v0) =

‎base/array.jl

+5-5
Original file line numberDiff line numberDiff line change
@@ -1378,7 +1378,7 @@ function findin(a, b)
13781378
ind = Array(Int, 0)
13791379
bset = union!(Set(), b)
13801380
for i = 1:length(a)
1381-
if contains(bset, a[i])
1381+
if in(a[i], bset)
13821382
push!(ind, i)
13831383
end
13841384
end
@@ -1424,7 +1424,7 @@ function gen_reducedim_func(n, f)
14241424
rvars = { symbol(string("r",i)) for i=1:n }
14251425
setlims = { quote
14261426
# each dim of reduction is either 1:sizeA or ivar:ivar
1427-
if contains(region,$i)
1427+
if in($i,region)
14281428
$(lo[i]) = 1
14291429
$(hi[i]) = size(A,$i)
14301430
else
@@ -1573,7 +1573,7 @@ function intersect(vs...)
15731573
for v_elem in vs[1]
15741574
inall = true
15751575
for i = 2:length(vs)
1576-
if !contains(vs[i], v_elem)
1576+
if !in(v_elem, vs[i])
15771577
inall=false; break
15781578
end
15791579
end
@@ -1589,7 +1589,7 @@ function union(vs...)
15891589
seen = Set()
15901590
for v in vs
15911591
for v_elem in v
1592-
if !contains(seen, v_elem)
1592+
if !in(v_elem, seen)
15931593
push!(ret, v_elem)
15941594
push!(seen, v_elem)
15951595
end
@@ -1604,7 +1604,7 @@ function setdiff(a, b)
16041604
ret = Array(args_type,0)
16051605
seen = Set()
16061606
for a_elem in a
1607-
if !contains(seen, a_elem) && !contains(bset, a_elem)
1607+
if !in(a_elem, seen) && !in(a_elem, bset)
16081608
push!(ret, a_elem)
16091609
push!(seen, a_elem)
16101610
end

‎base/client.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,10 @@ function process_options(args::Array{Any,1})
256256
global have_color = true
257257
elseif args[i][8] == '='
258258
val = args[i][9:]
259-
if contains(("no","0","false"), val)
259+
if in(val, ("no","0","false"))
260260
color_set = true
261261
global have_color = false
262-
elseif contains(("yes","1","true"), val)
262+
elseif in(val, ("yes","1","true"))
263263
color_set = true
264264
global have_color = true
265265
end

‎base/datafmt.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ const valid_opts = [:has_header, :ignore_invalid_chars, :use_mmap]
8686
function val_opts(opts)
8787
d = Dict{Symbol,Bool}()
8888
for opt in opts
89-
!contains(valid_opts, opt[1]) && error("unknown option $(opt[1])")
89+
!in(opt[1], valid_opts) && error("unknown option $(opt[1])")
9090
!isa(opt[2], Bool) && error("$(opt[1]) can only be boolean")
9191
d[opt[1]] = opt[2]
9292
end
@@ -148,7 +148,7 @@ function dlm_offsets(sbuff::UTF8String, dlm, eol, offsets::Array{Int,2})
148148
idx = 1
149149
while(idx <= length(sbuff.data))
150150
val,idx = next(sbuff, idx)
151-
(val != eol) && ((dlm == invalid_dlm) ? !contains(_default_delims, val) : (val != dlm)) && continue
151+
(val != eol) && ((dlm == invalid_dlm) ? !in(val, _default_delims) : (val != dlm)) && continue
152152
col += 1
153153
offsets[row,col] = idx-2
154154
(row >= maxrow) && (col == maxcol) && break
@@ -164,7 +164,7 @@ function dlm_offsets(dbuff::Vector{Uint8}, dlm::Uint8, eol::Uint8, offsets::Arra
164164
offsets[maxrow,maxcol] = length(dbuff)
165165
for idx in 1:length(dbuff)
166166
val = dbuff[idx]
167-
(val != eol) && ((dlm == invalid_dlm) ? !contains(_default_delims, val) : (val != dlm)) && continue
167+
(val != eol) && ((dlm == invalid_dlm) ? !in(val, _default_delims) : (val != dlm)) && continue
168168
col += 1
169169
offsets[row,col] = idx-1
170170
(row >= maxrow) && (col == maxcol) && break
@@ -178,7 +178,7 @@ function dlm_dims{T,D}(dbuff::T, eol::D, dlm::D)
178178
ncols = nrows = col = 0
179179
try
180180
for val in dbuff
181-
(val != eol) && ((dlm == invalid_dlm) ? !contains(_default_delims, val) : (val != dlm)) && continue
181+
(val != eol) && ((dlm == invalid_dlm) ? !in(val, _default_delims) : (val != dlm)) && continue
182182
col += 1
183183
(val == eol) && (nrows += 1; ncols = max(ncols, col); col = 0)
184184
end

‎base/dict.jl

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ abstract Associative{K,V}
44

55
const secret_table_token = :__c782dbf1cf4d6a2e5e3865d7e95634f2e09b5902__
66

7-
haskey(d::Associative, k) = contains(keys(d),k)
7+
haskey(d::Associative, k) = in(k,keys(d))
88

9-
function contains(a::Associative, p::(Any,Any))
9+
function in(p::(Any,Any), a::Associative)
1010
v = get(a,p[1],secret_table_token)
1111
!is(v, secret_table_token) && isequal(v, p[2])
1212
end
@@ -58,8 +58,8 @@ function next(v::ValueIterator, state)
5858
n[1][2], n[2]
5959
end
6060

61-
contains(v::KeyIterator, k) = !is(get(v.dict, k, secret_table_token),
62-
secret_table_token)
61+
in(k, v::KeyIterator) = !is(get(v.dict, k, secret_table_token),
62+
secret_table_token)
6363

6464
keys(a::Associative) = KeyIterator(a)
6565
values(a::Associative) = ValueIterator(a)
@@ -495,7 +495,7 @@ function get{K,V}(h::Dict{K,V}, key, deflt)
495495
end
496496

497497
haskey(h::Dict, key) = (ht_keyindex(h, key) >= 0)
498-
contains{T<:Dict}(v::KeyIterator{T}, key) = (ht_keyindex(v.dict, key) >= 0)
498+
in{T<:Dict}(key, v::KeyIterator{T}) = (ht_keyindex(v.dict, key) >= 0)
499499

500500
function getkey{K,V}(h::Dict{K,V}, key, deflt)
501501
index = ht_keyindex(h, key)

‎base/env.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const ENV = EnvHash()
7272

7373
getindex(::EnvHash, k::String) = @accessEnv k throw(KeyError(k))
7474
get(::EnvHash, k::String, def) = @accessEnv k (return def)
75-
contains(::KeyIterator{EnvHash}, k::String) = _hasenv(k)
75+
in(k::String, ::KeyIterator{EnvHash}) = _hasenv(k)
7676
pop!(::EnvHash, k::String) = (v = ENV[k]; _unsetenv(k); v)
7777
pop!(::EnvHash, k::String, def) = haskey(ENV,k) ? pop!(ENV,k) : def
7878
function delete!(::EnvHash, k::String)

‎base/exports.jl

+1
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,7 @@ export
693693
getindex,
694694
getkey,
695695
haskey,
696+
in,
696697
intersect!,
697698
intersect,
698699
isempty,

‎base/help.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function init_help()
6767
if !haskey(MODULE_DICT, func)
6868
MODULE_DICT[func] = {}
6969
end
70-
if !contains(MODULE_DICT[func], mod)
70+
if !in(mod, MODULE_DICT[func])
7171
push!(MODULE_DICT[func], mod)
7272
end
7373
end

‎base/intset.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ function copy!(to::IntSet, from::IntSet)
117117
union!(to, from)
118118
end
119119

120-
function contains(s::IntSet, n::Integer)
120+
function in(n::Integer, s::IntSet)
121121
if n >= s.limit
122122
# max IntSet length is typemax(Int), so highest possible element is
123123
# typemax(Int)-1

‎base/meta.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ export quot,
1010
quot(ex) = Expr(:quote, ex)
1111

1212
isexpr(ex::Expr, head) = ex.head === head
13-
isexpr(ex::Expr, heads::Set) = contains(heads, ex.head)
14-
isexpr(ex::Expr, heads::Vector) = contains(heads, ex.head)
13+
isexpr(ex::Expr, heads::Set) = in(ex.head, heads)
14+
isexpr(ex::Expr, heads::Vector) = in(ex.head, heads)
1515
isexpr(ex, head) = false
1616

1717
isexpr(ex, head, n::Int) = isexpr(ex, head) && length(ex.args) == n

‎base/multi.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ type ProcessExitedException <: Exception end
276276
worker_from_id(i) = worker_from_id(PGRP, i)
277277
function worker_from_id(pg::ProcessGroup, i)
278278
# Processes with pids > ours, have to connect to us. May not have happened. Wait for some time.
279-
if contains(map_del_wrkr, i)
279+
if in(i, map_del_wrkr)
280280
throw(ProcessExitedException())
281281
end
282282
if myid()==1 && !haskey(map_pid_wrkr,i)
@@ -330,7 +330,7 @@ function deregister_worker(pg, pid)
330330
ids = {}
331331
tonotify = {}
332332
for (id,rv) in pg.refs
333-
if contains(rv.clientset,pid)
333+
if in(pid,rv.clientset)
334334
push!(ids, id)
335335
end
336336
if rv.waitingfor == pid
@@ -465,7 +465,7 @@ function send_del_client(rr::RemoteRef)
465465
if rr.where == myid()
466466
del_client(rr2id(rr), myid())
467467
else
468-
if contains(map_del_wrkr, rr.where)
468+
if in(rr.where, map_del_wrkr)
469469
# for a removed worker, don't bother
470470
return
471471
end
@@ -883,7 +883,7 @@ function create_message_handler_loop(sock::AsyncStream) #returns immediately
883883

884884
if (myid() == 1)
885885
global rmprocset
886-
if contains(rmprocset, iderr)
886+
if in(iderr, rmprocset)
887887
delete!(rmprocset, iderr)
888888
else
889889
println("Worker $iderr terminated.")

‎base/number.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ start(x::Number) = false
3434
next(x::Number, state) = (x, true)
3535
done(x::Number, state) = state
3636
isempty(x::Number) = false
37-
contains(x::Number, y::Number) = x == y
37+
in(x::Number, y::Number) = x == y
3838

3939
reinterpret{T<:Real}(::Type{T}, x::Real) = box(T,x)
4040

‎base/pkg.jl

+5-5
Original file line numberDiff line numberDiff line change
@@ -303,12 +303,12 @@ function __fixup(
303303
exclude = []
304304
)
305305
sort!(instlist, lt=function(a,b)
306-
c = contains(Read.alldependencies(a,avail,free,fixed),b)
307-
nonordered = (!c && !contains(Read.alldependencies(b,avail,free,fixed),a))
306+
c = in(b,Read.alldependencies(a,avail,free,fixed))
307+
nonordered = (!c && !in(a,Read.alldependencies(b,avail,free,fixed)))
308308
nonordered ? a < b : c
309309
end)
310310
for p in instlist
311-
contains(exclude,p) && continue
311+
in(p,exclude) && continue
312312
build(p,["fixup"]) || return
313313
end
314314
end
@@ -325,9 +325,9 @@ function _fixup{T<:String}(
325325
oldlength = length(tofixup)
326326
while true
327327
for (p,_) in inst
328-
contains(tofixup,p) && continue
328+
in(p,tofixup) && continue
329329
for pf in tofixup
330-
if contains(Read.alldependencies(p,avail,free,fixed),pf)
330+
if in(pf,Read.alldependencies(p,avail,free,fixed))
331331
push!(tofixup,p)
332332
break
333333
end

‎base/pkg/query.jl

+6-6
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ function diff(have::Dict, want::Dict, avail::Dict, fixed::Dict)
6161
# Sort packages topologically
6262
sort!(changes, lt=function(a,b)
6363
((a,vera),(b,verb)) = (a,b)
64-
c = contains(Pkg.Read.alldependencies(a,avail,want,fixed),b)
65-
unnordered = (!c && !contains(Pkg.Read.alldependencies(b,avail,want,fixed),a))
64+
c = in(b,Pkg.Read.alldependencies(a,avail,want,fixed))
65+
unnordered = (!c && !in(a,Pkg.Read.alldependencies(b,avail,want,fixed)))
6666
unnordered ? a < b : c
6767
end)
6868

@@ -93,7 +93,7 @@ function prune_versions(reqs::Requires, deps::Dict{ByteString,Dict{VersionNumber
9393
allowed[p] = (VersionNumber=>Bool)[]
9494
allowedp = allowed[p]
9595
for (vn,_) in deps[p]
96-
allowedp[vn] = contains(vs, vn)
96+
allowedp[vn] = in(vn, vs)
9797
end
9898
@assert !isempty(allowedp)
9999
any([a for (_,a) in allowedp]) ||
@@ -162,7 +162,7 @@ function prune_versions(reqs::Requires, deps::Dict{ByteString,Dict{VersionNumber
162162
@assert haskey(vmask, p)
163163
vmaskp = vmask[p]
164164
for (vn,vm) in vmaskp
165-
push!(vm, contains(vs, vn))
165+
push!(vm, in(vn, vs))
166166
end
167167
end
168168

@@ -227,7 +227,7 @@ function prune_versions(reqs::Requires, deps::Dict{ByteString,Dict{VersionNumber
227227
new_deps[p] = (VersionNumber=>Available)[]
228228
pruned_versp = pruned_vers[p]
229229
for (vn,a) in depsp
230-
contains(pruned_versp, vn) || continue
230+
in(vn, pruned_versp) || continue
231231
new_deps[p][vn] = a
232232
end
233233
end
@@ -269,7 +269,7 @@ function dependencies_subset(deps::Dict{ByteString,Dict{VersionNumber,Available}
269269
while !isempty(staged)
270270
staged_next = Set{ByteString}()
271271
for p in staged, (_,a) in deps[p], (rp,_) in a.requires
272-
if !contains(allpkgs, rp)
272+
if !in(rp, allpkgs)
273273
push!(staged_next, rp)
274274
end
275275
end

‎base/pkg/read.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ function alldependencies(pkg::String,avail::Dict=available(),free::Dict=free(ins
146146
deps = [ k for (k,v) in dependencies(pkg,avail,free,fix) ]
147147
alldeps = copy(deps)
148148
for dep in deps
149-
dep != "julia" && !contains(alldeps,dep) && append!(alldeps,[ k for (k,v) in alldependencies(dep,avail,free,fix) ])
149+
dep != "julia" && !in(dep,alldeps) && append!(alldeps,[ k for (k,v) in alldependencies(dep,avail,free,fix) ])
150150
end
151151
alldeps
152152
end

‎base/pkg/resolve/interface.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ function verify_solution(sol::Vector{Int}, interface::Interface)
132132
p0 = pdict[p]
133133
@assert sol[p0] != spp[p0]
134134
vn = pvers[p0][sol[p0]]
135-
@assert contains(vs, vn)
135+
@assert in(vn, vs)
136136
end
137137

138138
# verify dependencies
@@ -146,7 +146,7 @@ function verify_solution(sol::Vector{Int}, interface::Interface)
146146
p1 = pdict[rp]
147147
@assert sol[p1] != spp[p1]
148148
vn = pvers[p1][sol[p1]]
149-
@assert contains(rvs, vn)
149+
@assert in(vn, rvs)
150150
end
151151
end
152152
end
@@ -210,7 +210,7 @@ function enforce_optimality!(sol::Vector{Int}, interface::Interface)
210210
break
211211
end
212212
vn = pvers[p1][sol[p1]]
213-
if !contains(vs, vn)
213+
if !in(vn, vs)
214214
# the dependency is violated because
215215
# the other package version is invalid
216216
viol = true
@@ -229,7 +229,7 @@ function enforce_optimality!(sol::Vector{Int}, interface::Interface)
229229
continue
230230
end
231231
vn = pvers[p0][s0+1]
232-
if !contains(vs, vn)
232+
if !in(vn, vs)
233233
# bumping the version would violate
234234
# the dependency
235235
viol = true

‎base/pkg/resolve/maxsum.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ type Graph
137137
end
138138

139139
for v1 = 1:length(pvers[p1])
140-
if !contains(rvs, pvers[p1][v1])
140+
if !in(pvers[p1][v1], rvs)
141141
bm[v1, v0] = false
142142
bmt[v0, v1] = false
143143
end
@@ -200,7 +200,7 @@ type Messages
200200
fld0 = fld[p0]
201201
for v0 = 1:spp[p0]-1
202202
vn = pvers0[v0]
203-
if !contains(rvs, vn)
203+
if !in(vn, rvs)
204204
# the state is forbidden by requirements
205205
fld0[v0] = FieldValue(-1)
206206
else

0 commit comments

Comments
 (0)
Please sign in to comment.