From 9296f4f65d6985f1a6bcd865fc140bb95d5150ec Mon Sep 17 00:00:00 2001 From: Stefan Karpinski Date: Thu, 26 Apr 2012 15:06:04 -0400 Subject: [PATCH] rename: HashTable => Dict, IdTable => ObjectIdDict [closes #766]. --- base/array.jl | 12 ++--- base/client.jl | 2 +- base/inference.jl | 20 ++++---- base/intfuncs.jl | 4 +- base/multi.jl | 12 ++--- base/process.jl | 4 +- base/serialize.jl | 6 +-- base/set.jl | 6 +-- base/sysimg.jl | 28 +++++------ base/table.jl | 110 +++++++++++++++++++++--------------------- base/task.jl | 4 +- base/util.jl | 4 +- examples/wordcount.jl | 10 ++-- extras/bitarray.jl | 16 +++--- extras/cairo.jl | 8 +-- extras/dicom.jl | 2 +- extras/inifile.jl | 6 +-- extras/lru.jl | 8 +-- extras/options.jl | 6 +-- extras/plot.jl | 2 +- extras/trie.jl | 4 +- extras/winston.jl | 76 ++++++++++++++--------------- src/dump.c | 6 +-- test/corelib.jl | 4 +- 24 files changed, 181 insertions(+), 179 deletions(-) diff --git a/base/array.jl b/base/array.jl index 13ff81d6435fe..861a932fa91f5 100644 --- a/base/array.jl +++ b/base/array.jl @@ -203,7 +203,7 @@ function ref(A::Array, I::Indices...) X = similar(A, d[1:i]) if is(ref_cache,nothing) - ref_cache = HashTable() + ref_cache = Dict() end gen_cartesian_map(ref_cache, ivars -> quote X[storeind] = A[$(ivars...)] @@ -358,7 +358,7 @@ let assign_cache = nothing global assign function assign(A::Array, x, I0::Indices, I::Indices...) if is(assign_cache,nothing) - assign_cache = HashTable() + assign_cache = Dict() end gen_cartesian_map(assign_cache, ivars->:(A[$(ivars...)] = x), tuple(I0, I...), @@ -372,7 +372,7 @@ let assign_cache = nothing global assign function assign(A::Array, X::AbstractArray, I0::Indices, I::Indices...) if is(assign_cache,nothing) - assign_cache = HashTable() + assign_cache = Dict() end gen_cartesian_map(assign_cache, ivars->:(A[$(ivars...)] = X[refind]; refind += 1), @@ -926,7 +926,7 @@ function findn{T}(A::StridedArray{T}) ranges = ntuple(ndims(A), d->(1:size(A,d))) if is(findn_cache,nothing) - findn_cache = HashTable() + findn_cache = Dict() end gen_cartesian_map(findn_cache, findn_one, ranges, @@ -1023,7 +1023,7 @@ function areduce(f::Function, A::StridedArray, region::Region, v0, RType::Type) R = similar(A, RType, dimsR) if is(areduce_cache,nothing) - areduce_cache = HashTable() + areduce_cache = Dict() end key = ndimsA @@ -1345,7 +1345,7 @@ function permute(A::StridedArray, perm) end if is(permute_cache,nothing) - permute_cache = HashTable() + permute_cache = Dict() end gen_cartesian_map(permute_cache, permute_one, ranges, diff --git a/base/client.jl b/base/client.jl index 7672220186912..c0d2796378c8d 100644 --- a/base/client.jl +++ b/base/client.jl @@ -187,7 +187,7 @@ function _start() ccall(:jl_register_toplevel_eh, Void, ()) ccall(:jl_start_io_thread, Void, ()) global const Workqueue = WorkItem[] - global const Waiting = HashTable(64) + global const Waiting = Dict(64) if !anyp(a->(a=="--worker"), ARGS) # start in "head node" mode diff --git a/base/inference.jl b/base/inference.jl index fc48ca5e4e0bd..8e920d7d79601 100644 --- a/base/inference.jl +++ b/base/inference.jl @@ -60,7 +60,7 @@ isType(t::ANY) = isa(t,AbstractKind) && is((t::AbstractKind).name,Type.name) isseqtype(t::ANY) = isa(t,AbstractKind) && is((t::AbstractKind).name.name,:...) -const t_func = IdTable() +const t_func = ObjectIdDict() #t_func[tuple] = (0, Inf, (args...)->limit_tuple_depth(args)) t_func[throw] = (1, 1, x->None) t_func[boxsi8] = (1, 1, x->Int8) @@ -318,7 +318,7 @@ function builtin_tfunction(f::ANY, args::ANY, argtypes::ANY) if is(f,tuple) return limit_tuple_depth(argtypes) end - tf = get(t_func::IdTable, f, false) + tf = get(t_func::ObjectIdDict, f, false) if is(tf,false) # struct constructor if isa(f, CompositeKind) @@ -342,7 +342,7 @@ end type StaticVarInfo sp::Tuple - cenv::IdTable # types of closed vars + cenv::ObjectIdDict # types of closed vars end function a2t(a::AbstractVector) @@ -679,7 +679,7 @@ abstract_eval(s::SymbolNode, vtypes, sv::StaticVarInfo) = abstract_eval(x, vtypes, sv::StaticVarInfo) = abstract_eval_constant(x) -typealias VarTable IdTable +typealias VarTable ObjectIdDict type StateUpdate var::Symbol @@ -778,12 +778,12 @@ end function stupdate(state, changes::Union(StateUpdate,VarTable), vars) if is(state,()) - state = IdTable() + state = ObjectIdDict() end for i = 1:length(vars) v = vars[i] newtype = changes[v] - oldtype = get(state::IdTable,v,NF) + oldtype = get(state::ObjectIdDict,v,NF) if tchanged(newtype, oldtype) state[v] = tmerge(oldtype, newtype) end @@ -931,7 +931,7 @@ function typeinf(linfo::LambdaStaticData,atypes::Tuple,sparams::Tuple, def, cop) # initial set of pc add(W,1) # initial types - s[1] = IdTable() + s[1] = ObjectIdDict() for v in vars s[1][v] = Undef end @@ -949,7 +949,7 @@ function typeinf(linfo::LambdaStaticData,atypes::Tuple,sparams::Tuple, def, cop) s[1][args[i]] = atypes[i] end # types of closed vars - cenv = IdTable() + cenv = ObjectIdDict() for vi = ((ast.args[2][3])::Array{Any,1}) vi::Array{Any,1} vname = vi[1] @@ -1108,7 +1108,7 @@ function typeinf(linfo::LambdaStaticData,atypes::Tuple,sparams::Tuple, def, cop) end function record_var_type(e::Symbol, t, decls) - otherTy = get(decls::IdTable, e, false) + otherTy = get(decls::ObjectIdDict, e, false) # keep track of whether a variable is always the same type if !is(otherTy,false) if !is(otherTy, t) @@ -1175,7 +1175,7 @@ end # annotate types of all symbols in AST function type_annotate(ast::Expr, states::Array{Any,1}, sv::ANY, rettype::ANY, vnames::ANY) - decls = IdTable() + decls = ObjectIdDict() closures = LambdaStaticData[] body = ast.args[3].args::Array{Any,1} for i=1:length(body) diff --git a/base/intfuncs.jl b/base/intfuncs.jl index 9d8ba1cbce08e..7e9b2b029e13f 100644 --- a/base/intfuncs.jl +++ b/base/intfuncs.jl @@ -276,7 +276,7 @@ bits(x::Union(Int64,Uint64,Float64)) = bin(reinterpret(Uint64,x), 64) # TODO: maybe implement a proper Eratosthenes's sieve. -function factor{T<:Integer}(n::T, h::HashTable{T,Int}) +function factor{T<:Integer}(n::T, h::Dict{T,Int}) if n <= 0 error("factor: number to be factored must be positive") end @@ -298,4 +298,4 @@ function factor{T<:Integer}(n::T, h::HashTable{T,Int}) h[n] = get(h,n,0)+1 return h end -factor{T<:Integer}(n::T) = factor(n, HashTable{T,Int}()) +factor{T<:Integer}(n::T) = factor(n, Dict{T,Int}()) diff --git a/base/multi.jl b/base/multi.jl index fac65a322e4af..49ec9cbe35db4 100644 --- a/base/multi.jl +++ b/base/multi.jl @@ -179,10 +179,10 @@ type ProcessGroup np::Int # global references - refs::HashTable + refs::Dict function ProcessGroup(myid::Integer, w::Array{Any,1}, locs::Array{Any,1}) - return new(myid, w, locs, length(w), HashTable()) + return new(myid, w, locs, length(w), Dict()) end end @@ -192,7 +192,7 @@ function add_workers(PGRP::ProcessGroup, w::Array{Any,1}) # NOTE: currently only node 1 can add new nodes, since nobody else # has the full list of address:port newlocs = append(PGRP.locs, locs) - sockets = HashTable() + sockets = Dict() handler = fd->message_handler(fd, sockets) for i=1:n push(PGRP.workers, w[i]) @@ -269,7 +269,7 @@ end ## remote refs and core messages: do, call, fetch, wait, ref, put ## -const _jl_client_refs = WeakKeyHashTable() +const _jl_client_refs = WeakKeyDict() type RemoteRef where::Int @@ -958,7 +958,7 @@ function start_worker(wrfd) global const Scheduler = current_task() - worker_sockets = HashTable() + worker_sockets = Dict() add_fd_handler(sockfd, fd->accept_handler(fd, worker_sockets)) try @@ -1554,7 +1554,7 @@ end yield() = yieldto(Scheduler) -const _jl_fd_handlers = HashTable() +const _jl_fd_handlers = Dict() add_fd_handler(fd::Int32, H) = (_jl_fd_handlers[fd]=H) del_fd_handler(fd::Int32) = del(_jl_fd_handlers, fd) diff --git a/base/process.jl b/base/process.jl index a3af15377cbf3..8dd21d44b4965 100644 --- a/base/process.jl +++ b/base/process.jl @@ -160,7 +160,7 @@ end type Cmd exec::Executable - pipes::HashTable{FileDes,PipeEnd} + pipes::Dict{FileDes,PipeEnd} pipeline::Set{Cmd} pid::Int32 status::ProcessStatus @@ -171,7 +171,7 @@ type Cmd error("Cmd: too few words to exec") end this = new(exec, - HashTable{FileDes,PipeEnd}(), + Dict{FileDes,PipeEnd}(), Set{Cmd}(), 0, ProcessNotRun(), diff --git a/base/serialize.jl b/base/serialize.jl index af2f316e1af73..10d4db8678a85 100644 --- a/base/serialize.jl +++ b/base/serialize.jl @@ -5,8 +5,8 @@ abstract LongSymbol abstract LongTuple abstract LongExpr -const _jl_ser_tag = IdTable() -const _jl_deser_tag = IdTable() +const _jl_ser_tag = ObjectIdDict() +const _jl_deser_tag = ObjectIdDict() let i = 2 global _jl_ser_tag, _jl_deser_tag for t = {Symbol, Int8, Uint8, Int16, Uint16, Int32, Uint32, @@ -238,7 +238,7 @@ deserialize_tuple(s, len) = (a = ntuple(len, i->deserialize(s)); deserialize(s, ::Type{Symbol}) = symbol(read(s, Uint8, int32(read(s, Uint8)))) deserialize(s, ::Type{LongSymbol}) = symbol(read(s, Uint8, read(s, Int32))) -const _jl_known_lambda_data = HashTable() +const _jl_known_lambda_data = Dict() function deserialize(s, ::Type{Function}) b = read(s, Uint8) diff --git a/base/set.jl b/base/set.jl index 022370f02be93..393d82bf72c80 100644 --- a/base/set.jl +++ b/base/set.jl @@ -1,8 +1,8 @@ type Set{T} - hash::HashTable{T,Bool} + hash::Dict{T,Bool} - Set() = new(HashTable{T,Bool}()) - Set(x...) = add_each(new(HashTable{T,Bool}(length(x))), x) + Set() = new(Dict{T,Bool}()) + Set(x...) = add_each(new(Dict{T,Bool}(length(x))), x) end Set() = Set{Any}() Set(x...) = Set{Any}(x...) diff --git a/base/sysimg.jl b/base/sysimg.jl index b02197acaec48..066460f9db44e 100644 --- a/base/sysimg.jl +++ b/base/sysimg.jl @@ -98,13 +98,13 @@ include("signal_fftw.jl") # prime method cache with some things we know we'll need right after startup length(1:2:3) -(HashTable(0)[1])=()->() +(Dict(0)[1])=()->() numel(intset()) has(intset(),2) del_all(FDSet()) -start(HashTable(0)) -done(HashTable(0),0) -get(HashTable(0), 0, ()) +start(Dict(0)) +done(Dict(0),0) +get(Dict(0), 0, ()) add(FDSet(),int32(0)) 2==2.0 2.0==2.0 @@ -116,25 +116,25 @@ compile_hint(getcwd, ()) compile_hint(fdio, (Int32,)) compile_hint(ProcessGroup, (Int, Array{Any,1}, Array{Any,1})) compile_hint(select_read, (FDSet, Float64)) -compile_hint(next, (HashTable{Any,Any}, Int)) -compile_hint(start, (HashTable{Any,Any},)) +compile_hint(next, (Dict{Any,Any}, Int)) +compile_hint(start, (Dict{Any,Any},)) compile_hint(perform_work, ()) compile_hint(isempty, (Array{Any,1},)) compile_hint(isempty, (Array{WorkItem,1},)) -compile_hint(ref, (HashTable{Any,Any}, Int32)) +compile_hint(ref, (Dict{Any,Any}, Int32)) compile_hint(event_loop, (Bool,)) compile_hint(_start, ()) compile_hint(process_options, (Array{Any,1},)) compile_hint(run_repl, ()) compile_hint(anyp, (Function, Array{Any,1})) -compile_hint(HashTable, (Int,)) -compile_hint(HashTable{Any,Any}, (Int,)) +compile_hint(Dict, (Int,)) +compile_hint(Dict{Any,Any}, (Int,)) compile_hint(Set, ()) -compile_hint(assign, (HashTable{Any,Any}, Bool, Cmd)) -compile_hint(rehash, (HashTable{Any,Any}, Int)) +compile_hint(assign, (Dict{Any,Any}, Bool, Cmd)) +compile_hint(rehash, (Dict{Any,Any}, Int)) compile_hint(run, (Cmd,)) compile_hint(spawn, (Cmd,)) -compile_hint(assign, (HashTable{Any,Any}, Bool, FileDes)) +compile_hint(assign, (Dict{Any,Any}, Bool, FileDes)) compile_hint(wait, (Int32,)) compile_hint(system_error, (ASCIIString, Bool)) compile_hint(SystemError, (ASCIIString,)) @@ -150,7 +150,7 @@ compile_hint(open, (ASCIIString, Bool, Bool, Bool, Bool)) compile_hint(srand, (Uint64,)) compile_hint(done, (IntSet, Int64)) compile_hint(next, (IntSet, Int64)) -compile_hint(ht_keyindex, (HashTable{Any,Any}, Int32)) +compile_hint(ht_keyindex, (Dict{Any,Any}, Int32)) compile_hint(perform_work, (WorkItem,)) compile_hint(notify_done, (WorkItem,)) compile_hint(work_result, (WorkItem,)) @@ -197,7 +197,7 @@ compile_hint(_ieval, (Symbol,)) compile_hint(static_convert, (Any, Any)) compile_hint(assign, (Array{Any,1}, WeakRef, Int)) compile_hint(hash, (Tuple,)) -compile_hint(assign, (HashTable{Any,Any}, WorkItem, (Int,Int))) +compile_hint(assign, (Dict{Any,Any}, WorkItem, (Int,Int))) compile_hint(isequal, ((Int,Int),(Int,Int))) compile_hint(RemoteRef, (Int, Int, Int)) compile_hint(inlining_pass, (LambdaStaticData, Array{Any,1})) diff --git a/base/table.jl b/base/table.jl index ca76030b1dff9..5b26b8f3cba1c 100644 --- a/base/table.jl +++ b/base/table.jl @@ -29,40 +29,42 @@ function show(t::Associative) print(typeof(t).name.name,"()") else print("{") + first = true for (k, v) = t + first || print(',') + first = false show(k) print("=>") show(v) - print(",") end print("}") end end -type IdTable <: Associative +type ObjectIdDict <: Associative ht::Array{Any,1} - IdTable(sz::Integer) = new(cell(2*_tablesz(sz))) - IdTable() = IdTable(0) + ObjectIdDict(sz::Integer) = new(cell(2*_tablesz(sz))) + ObjectIdDict() = ObjectIdDict(0) end -function assign(t::IdTable, v::ANY, k::ANY) +function assign(t::ObjectIdDict, v::ANY, k::ANY) t.ht = ccall(:jl_eqtable_put, Any, (Any, Any, Any), t.ht, k, v)::Array{Any,1} return t end -get(t::IdTable, key::ANY, default::ANY) = +get(t::ObjectIdDict, key::ANY, default::ANY) = ccall(:jl_eqtable_get, Any, (Any, Any, Any), t.ht, key, default) -del(t::IdTable, key::ANY) = +del(t::ObjectIdDict, key::ANY) = (ccall(:jl_eqtable_del, Int32, (Any, Any), t.ht, key); t) -del_all(t::IdTable) = (t.ht = cell(length(t.ht)); t) +del_all(t::ObjectIdDict) = (t.ht = cell(length(t.ht)); t) -start(t::IdTable) = 0 -done(t::IdTable, i) = is(next(t,i),()) -next(t::IdTable, i) = ccall(:jl_eqtable_next, Any, (Any, Uint32), t.ht, i) +start(t::ObjectIdDict) = 0 +done(t::ObjectIdDict, i) = is(next(t,i),()) +next(t::ObjectIdDict, i) = ccall(:jl_eqtable_next, Any, (Any, Uint32), t.ht, i) -isempty(t::IdTable) = is(next(t,0),()) +isempty(t::ObjectIdDict) = is(next(t,0),()) # hashing @@ -139,32 +141,32 @@ end # hash table -type HashTable{K,V} <: Associative +type Dict{K,V} <: Associative keys::Array{Any,1} vals::Array{Any,1} ndel::Int deleter::Function - HashTable() = HashTable{K,V}(0) - function HashTable(n::Integer) + Dict() = Dict{K,V}(0) + function Dict(n::Integer) n = _tablesz(n) new(fill!(cell(n), _jl_secret_table_token), fill!(cell(n), _jl_secret_table_token), 0, identity) end - function HashTable(ks::Tuple, vs::Tuple) + function Dict(ks::Tuple, vs::Tuple) n = length(ks) - h = HashTable{K,V}(n) + h = Dict{K,V}(n) for i=1:n h[ks[i]] = vs[i] end return h end end -HashTable() = HashTable(0) -HashTable(n::Integer) = HashTable{Any,Any}(n) +Dict() = Dict(0) +Dict(n::Integer) = Dict{Any,Any}(n) -function serialize(s, t::HashTable) +function serialize(s, t::Dict) serialize_type(s, typeof(t)) write(s, int32(length(t))) for (k,v) in t @@ -173,7 +175,7 @@ function serialize(s, t::HashTable) end end -function deserialize(s, T::Type{HashTable}) +function deserialize(s, T::Type{Dict}) n = read(s, Int32) t = T(n) for i = 1:n @@ -185,14 +187,14 @@ function deserialize(s, T::Type{HashTable}) end # syntax entry point -hashtable{K,V}(ks::(K...), vs::(V...)) = HashTable{K,V} (ks, vs) -hashtable{K} (ks::(K...), vs::Tuple ) = HashTable{K,Any} (ks, vs) -hashtable{V} (ks::Tuple , vs::(V...)) = HashTable{Any,V} (ks, vs) -hashtable (ks::Tuple , vs::Tuple) = HashTable{Any,Any}(ks, vs) +hashtable{K,V}(ks::(K...), vs::(V...)) = Dict{K,V} (ks, vs) +hashtable{K} (ks::(K...), vs::Tuple ) = Dict{K,Any} (ks, vs) +hashtable{V} (ks::Tuple , vs::(V...)) = Dict{Any,V} (ks, vs) +hashtable (ks::Tuple , vs::Tuple) = Dict{Any,Any}(ks, vs) hashindex(key, sz) = (int(hash(key)) & (sz-1)) + 1 -function rehash{K,V}(h::HashTable{K,V}, newsz) +function rehash{K,V}(h::Dict{K,V}, newsz) oldk = copy(h.keys) oldv = copy(h.vals) sz = length(oldk) @@ -213,14 +215,14 @@ function rehash{K,V}(h::HashTable{K,V}, newsz) return h end -function del_all{K,V}(h::HashTable{K,V}) +function del_all{K,V}(h::Dict{K,V}) fill!(h.keys, _jl_secret_table_token) fill!(h.vals, _jl_secret_table_token) h.ndel = 0 return h end -function assign{K,V}(h::HashTable{K,V}, v, key) +function assign{K,V}(h::Dict{K,V}, v, key) key = convert(K,key) v = convert(V,v) @@ -279,7 +281,7 @@ function assign{K,V}(h::HashTable{K,V}, v, key) end # get the index where a key is stored, or -1 if not present -function ht_keyindex{K,V}(h::HashTable{K,V}, key) +function ht_keyindex{K,V}(h::Dict{K,V}, key) key = convert(K,key) sz = length(h.keys) @@ -307,17 +309,17 @@ function ht_keyindex{K,V}(h::HashTable{K,V}, key) return -1 end -function get(h::HashTable, key, deflt) +function get(h::Dict, key, deflt) index = ht_keyindex(h, key) return (index<0) ? deflt : h.vals[index] end -function key(h::HashTable, key, deflt) +function key(h::Dict, key, deflt) index = ht_keyindex(h, key) return (index<0) ? deflt : h.keys[index] end -function del(h::HashTable, key) +function del(h::Dict, key) index = ht_keyindex(h, key) if index > 0 h.vals[index] = _jl_secret_table_token @@ -334,12 +336,12 @@ function skip_deleted(vals, i) return i end -start(t::HashTable) = skip_deleted(t.vals, 1) -done(t::HashTable, i) = done(t.vals, i) -next(t::HashTable, i) = ((t.keys[i],t.vals[i]), skip_deleted(t.vals,i+1)) +start(t::Dict) = skip_deleted(t.vals, 1) +done(t::Dict, i) = done(t.vals, i) +next(t::Dict, i) = ((t.keys[i],t.vals[i]), skip_deleted(t.vals,i+1)) -isempty(t::HashTable) = done(t, start(t)) -function length(t::HashTable) +isempty(t::Dict) = done(t, start(t)) +function length(t::Dict) n = 0 for v in t.vals n += int(!is(v,_jl_secret_table_token)) @@ -347,7 +349,7 @@ function length(t::HashTable) return n end -function add_weak_key(t::HashTable, k, v) +function add_weak_key(t::Dict, k, v) if is(t.deleter, identity) t.deleter = x->del(t, x) end @@ -356,22 +358,22 @@ function add_weak_key(t::HashTable, k, v) return t end -function add_weak_value(t::HashTable, k, v) +function add_weak_value(t::Dict, k, v) t[k] = WeakRef(v) finalizer(v, x->del(t, k)) return t end -type WeakKeyHashTable{K,V} <: Associative - ht::HashTable{K,V} +type WeakKeyDict{K,V} <: Associative + ht::Dict{K,V} - WeakKeyHashTable() = new(HashTable{K,V}()) + WeakKeyDict() = new(Dict{K,V}()) end -WeakKeyHashTable() = WeakKeyHashTable{Any,Any}() +WeakKeyDict() = WeakKeyDict{Any,Any}() -assign(wkh::WeakKeyHashTable, v, key) = add_weak_key(wkh.ht, key, v) +assign(wkh::WeakKeyDict, v, key) = add_weak_key(wkh.ht, key, v) -function key(wkh::WeakKeyHashTable, kk, deflt) +function key(wkh::WeakKeyDict, kk, deflt) k = key(wkh.ht, kk, _jl_secret_table_token) if is(k, _jl_secret_table_token) return deflt @@ -379,13 +381,13 @@ function key(wkh::WeakKeyHashTable, kk, deflt) return k.value end -get(wkh::WeakKeyHashTable, key, deflt) = get(wkh.ht, key, deflt) -del(wkh::WeakKeyHashTable, key) = del(wkh.ht, key) -del_all(wkh::WeakKeyHashTable) = (del_all(wkh.ht); wkh) -has(wkh::WeakKeyHashTable, key) = has(wkh.ht, key) -ref(wkh::WeakKeyHashTable, key) = ref(wkh.ht, key) -isempty(wkh::WeakKeyHashTable) = isempty(wkh.ht) +get(wkh::WeakKeyDict, key, deflt) = get(wkh.ht, key, deflt) +del(wkh::WeakKeyDict, key) = del(wkh.ht, key) +del_all(wkh::WeakKeyDict) = (del_all(wkh.ht); wkh) +has(wkh::WeakKeyDict, key) = has(wkh.ht, key) +ref(wkh::WeakKeyDict, key) = ref(wkh.ht, key) +isempty(wkh::WeakKeyDict) = isempty(wkh.ht) -start(t::WeakKeyHashTable) = start(t.ht) -done(t::WeakKeyHashTable, i) = done(t.ht, i) -next(t::WeakKeyHashTable, i) = next(t.ht, i) +start(t::WeakKeyDict) = start(t.ht) +done(t::WeakKeyDict, i) = done(t.ht, i) +next(t::WeakKeyDict, i) = next(t.ht, i) diff --git a/base/task.jl b/base/task.jl index 8bf71c39737fb..9003232b7c731 100644 --- a/base/task.jl +++ b/base/task.jl @@ -4,9 +4,9 @@ show(t::Task) = print("Task") function tls() t = current_task() if is(t.tls, nothing) - t.tls = IdTable() + t.tls = ObjectIdDict() end - (t.tls)::IdTable + (t.tls)::ObjectIdDict end function tls(key) diff --git a/base/util.jl b/base/util.jl index 822e05b6e47bc..0cf3702069582 100644 --- a/base/util.jl +++ b/base/util.jl @@ -217,14 +217,14 @@ end # help function parse_help(stream) - helpdb = HashTable() + helpdb = Dict() for l = each_line(stream) if isempty(l) continue end if length(l) >= 3 && l[1:3]=="## " heading = l[4:end-1] - category = HashTable() + category = Dict() helpdb[heading] = category continue end diff --git a/examples/wordcount.jl b/examples/wordcount.jl index 2de8a92a7ba98..1768ac4015725 100644 --- a/examples/wordcount.jl +++ b/examples/wordcount.jl @@ -16,11 +16,11 @@ # julia> wordcount_files("/tmp/output.txt", "/tmp/input1.txt","/tmp/input2.txt",...) # "Map" function. -# Takes a string. Returns a HashTable with the number of times each word +# Takes a string. Returns a Dict with the number of times each word # appears in that string. function wordcount(text) words=split(text,(' ','\n','\t','-','.',',',':',';'),false) - counts=HashTable() + counts=Dict() for w = words counts[w]=get(counts,w,0)+1 end @@ -28,11 +28,11 @@ function wordcount(text) end # "Reduce" function. -# Takes a collection of HashTables in the format returned by wordcount() -# Returns a HashTable in which words that appear in multiple inputs +# Takes a collection of Dicts in the format returned by wordcount() +# Returns a Dict in which words that appear in multiple inputs # have their totals added together. function wcreduce(wcs) - counts=HashTable() + counts=Dict() for c = wcs for (k,v)=c counts[k] = get(counts,k,0)+v diff --git a/extras/bitarray.jl b/extras/bitarray.jl index 7b55218aa4db4..33f2162f42772 100644 --- a/extras/bitarray.jl +++ b/extras/bitarray.jl @@ -364,7 +364,7 @@ let ref_cache = nothing return X end if is(ref_cache,nothing) - ref_cache = HashTable() + ref_cache = Dict() end gap_lst = [last(r)-first(r)+1 | r in I] stride_lst = Array(Int, nI) @@ -415,7 +415,7 @@ let ref_cache = nothing X = similar(B, d) if is(ref_cache,nothing) - ref_cache = HashTable() + ref_cache = Dict() end gen_cartesian_map(ref_cache, ivars -> quote X[storeind] = B[$(ivars...)] @@ -513,7 +513,7 @@ let assign_cache = nothing return B end if is(assign_cache,nothing) - assign_cache = HashTable() + assign_cache = Dict() end gap_lst = [last(r)-first(r)+1 | r in I] stride_lst = Array(Int, nI) @@ -581,7 +581,7 @@ let assign_cache = nothing global assign function assign(B::BitArray, x::Number, I0::Indices, I::Indices...) if is(assign_cache,nothing) - assign_cache = HashTable() + assign_cache = Dict() end gen_cartesian_map(assign_cache, ivars->:(B[$(ivars...)] = x), tuple(I0, I...), @@ -599,7 +599,7 @@ let assign_cache = nothing global assign function assign{T<:Integer,S<:Number}(B::BitArray{T}, X::AbstractArray{S}, I0::Indices, I::Indices...) if is(assign_cache,nothing) - assign_cache = HashTable() + assign_cache = Dict() end gen_cartesian_map(assign_cache, ivars->:(B[$(ivars...)] = X[refind]; refind += 1), @@ -1244,7 +1244,7 @@ function findn(B::BitArray) ranges = ntuple(ndims(B), d->(1:size(B,d))) if is(findn_cache,nothing) - findn_cache = HashTable() + findn_cache = Dict() end gen_cartesian_map(findn_cache, findn_one, ranges, @@ -1310,7 +1310,7 @@ function bitareduce{T<:Integer}(f::Function, A::BitArray{T}, region::Region, v0) R = BitArray(T, dimsR) if is(bitareduce_cache,nothing) - bitareduce_cache = HashTable() + bitareduce_cache = Dict() end key = ndimsA @@ -1513,7 +1513,7 @@ function permute(B::BitArray, perm) end if is(permute_cache,nothing) - permute_cache = HashTable() + permute_cache = Dict() end gen_cartesian_map(permute_cache, permute_one, ranges, diff --git a/extras/cairo.jl b/extras/cairo.jl index 029639cf16a2b..e405542492406 100644 --- a/extras/cairo.jl +++ b/extras/cairo.jl @@ -248,10 +248,10 @@ end # ----------------------------------------------------------------------------- type RendererState - current::HashTable - saved::Vector{HashTable} + current::Dict + saved::Vector{Dict} - RendererState() = new(HashTable(),HashTable[]) + RendererState() = new(Dict(),Dict[]) end function set( self::RendererState, name, value ) @@ -273,7 +273,7 @@ end function save( self::RendererState ) enqueue( self.saved, self.current ) - self.current = HashTable() + self.current = Dict() end function restore( self::RendererState ) diff --git a/extras/dicom.jl b/extras/dicom.jl index 0306af3ff6d48..9f00dae1de1a2 100644 --- a/extras/dicom.jl +++ b/extras/dicom.jl @@ -1,7 +1,7 @@ include("dcm_dict.jl") function dcm_init() - dcm_dict = HashTable() + dcm_dict = Dict() for d in (_dcmdict_data_::Array{Any,1}) dcm_dict[(uint16(d[1][1]),uint16(d[1][2]))] = d[2:] end diff --git a/extras/inifile.jl b/extras/inifile.jl index f7902e08a4f5c..3407120546ac9 100644 --- a/extras/inifile.jl +++ b/extras/inifile.jl @@ -1,15 +1,15 @@ # .ini file parser let - typealias HTSS HashTable{String,String} + typealias HTSS Dict{String,String} global IniFile type IniFile - sections::HashTable{String,HTSS} + sections::Dict{String,HTSS} defaults::HTSS end - IniFile() = IniFile(HashTable{String,HTSS}(), HTSS()) + IniFile() = IniFile(Dict{String,HTSS}(), HTSS()) global read function read(inifile::IniFile, stream::IOStream) diff --git a/extras/lru.jl b/extras/lru.jl index add7b9b1f046b..6cce4ec14ad27 100644 --- a/extras/lru.jl +++ b/extras/lru.jl @@ -27,19 +27,19 @@ type CacheItem{K,V} end type UnboundedLRU{K,V} <: LRU{K,V} - ht::HashTable{K,CacheItem{K,V}} + ht::Dict{K,CacheItem{K,V}} q::Vector{CacheItem{K,V}} - UnboundedLRU() = new(HashTable{K,CacheItem{K,V}}(), similar(Array(CacheItem{K,V},1), 0)) + UnboundedLRU() = new(Dict{K,CacheItem{K,V}}(), similar(Array(CacheItem{K,V},1), 0)) end UnboundedLRU() = UnboundedLRU{Any, Any}() type BoundedLRU{K,V} <: LRU{K,V} - ht::HashTable + ht::Dict q::Vector{CacheItem} maxsize::Int - BoundedLRU(m) = new(HashTable(), similar(Array(CacheItem,1), 0), m) + BoundedLRU(m) = new(Dict(), similar(Array(CacheItem,1), 0), m) BoundedLRU() = BoundedLRU(__MAXCACHE) end BoundedLRU(m) = BoundedLRU{Any, Any}(m) diff --git a/extras/options.jl b/extras/options.jl index e9826bd3fa803..5da845a34643b 100644 --- a/extras/options.jl +++ b/extras/options.jl @@ -13,7 +13,7 @@ end type CheckError <: OptionsChecking end type Options{T<:OptionsChecking} - key2index::HashTable{Symbol,Int} + key2index::Dict{Symbol,Int} vals::Vector used::Vector{Bool} check_lock::Vector{Bool} @@ -31,7 +31,7 @@ function Options{T<:OptionsChecking}(::Type{T},args...) else ((), (), Array(Any, 0)) end - ht = HashTable{Symbol,Int}(keys,index) + ht = Dict{Symbol,Int}(keys,index) used = falses(n) check_lock = falses(n) Options{T}(ht,vals,used,check_lock) @@ -39,7 +39,7 @@ end # Constructor: supply type followed by list of assignment expressions, e.g., # o = Options(CheckNone,:(a=5),:(b=rand(3)),...) function Options{T<:OptionsChecking}(::Type{T},ex::Expr...) - ht = HashTable{Symbol,Int}() + ht = Dict{Symbol,Int}() vals = Array(Any,0) n = length(ex) for i = 1:n diff --git a/extras/plot.jl b/extras/plot.jl index f1e0f055fb169..ec155b6e15191 100644 --- a/extras/plot.jl +++ b/extras/plot.jl @@ -54,7 +54,7 @@ const chartokens = { } function _parse_style(spec::String) - style = HashTable() + style = Dict() for (k,v) in { "--" => "dashed", "-." => "dotdashed" } splitspec = split(spec, k) diff --git a/extras/trie.jl b/extras/trie.jl index e3d48f77208f0..a38ad5eebef49 100644 --- a/extras/trie.jl +++ b/extras/trie.jl @@ -1,12 +1,12 @@ type Trie{T} value::T - children::HashTable{Char,Trie{T}} + children::Dict{Char,Trie{T}} is_key::Bool function Trie() self = new() - self.children = HashTable{Char,Trie{T}}() + self.children = Dict{Char,Trie{T}}() self.is_key = false self end diff --git a/extras/winston.jl b/extras/winston.jl index eb183093d8817..fb560f33bbec7 100644 --- a/extras/winston.jl +++ b/extras/winston.jl @@ -61,7 +61,7 @@ begin return h end elseif x[1] == '{' && x[end] == '}' - style = HashTable() + style = Dict() pairs = map( strip, split(x[2:end-1], ',', false) ) for pair in pairs kv = split( pair, ':', false ) @@ -90,7 +90,7 @@ begin function config_options( sec::String ) global _winston_config - opts = HashTable() + opts = Dict() if sec == "defaults" for (k,v) in _winston_config.inifile.defaults opts[k] = _atox(v) @@ -107,7 +107,7 @@ end # utils ----------------------------------------------------------------------- function args2hashtable(args...) - opts = HashTable() + opts = Dict() if length(args) == 0 return opts end @@ -545,7 +545,7 @@ end # ============================================================================= abstract RenderObject -typealias RenderStyle HashTable{String,Union(Integer,Float,String)} +typealias RenderStyle Dict{String,Union(Integer,Float,String)} function kw_init( self::RenderObject, args...) for (k,v) in kw_defaults(self) @@ -895,7 +895,7 @@ type Legend <: PlotComponent function Legend( x, y, components, args... ) #_PlotComponent.__init__( self ) - self = new(HashTable()) + self = new(Dict()) conf_setattr( self ) kw_init(self, args...) self.x = x @@ -960,7 +960,7 @@ type ErrorBarsX <: ErrorBar hi function ErrorBarsX( y, lo, hi, args... ) - self = new(HashTable()) + self = new(Dict()) conf_setattr(self) kw_init(self, args...) self.y = y @@ -999,7 +999,7 @@ type ErrorBarsY <: ErrorBar hi function ErrorBarsY( x, lo, hi, args... ) - self = new(HashTable()) + self = new(Dict()) conf_setattr(self) kw_init(self, args...) self.x = x @@ -1274,7 +1274,7 @@ end abstract HalfAxis <: PlotComponent type HalfAxisX <: HalfAxis - attr::HashTable + attr::Dict func_ticks_default func_ticks_num func_subticks_default @@ -1282,7 +1282,7 @@ type HalfAxisX <: HalfAxis function HalfAxisX(args...) self = new( - HashTable(), + Dict(), (_ticks_default_linear, _ticks_default_log), (_ticks_num_linear, _ticks_num_log), (_subticks_linear, _subticks_log), @@ -1372,7 +1372,7 @@ function _make_grid( self::HalfAxisX, context, ticks ) end type HalfAxisY <: HalfAxis - attr::HashTable + attr::Dict func_ticks_default func_ticks_num func_subticks_default @@ -1380,7 +1380,7 @@ type HalfAxisY <: HalfAxis function HalfAxisY(args...) self = new( - HashTable(), + Dict(), (_ticks_default_linear, _ticks_default_log), (_ticks_num_linear, _ticks_num_log), (_subticks_linear, _subticks_log), @@ -1530,7 +1530,7 @@ function _make_ticklabels( self::HalfAxis, context, pos, labels ) halign, valign = _align(self) - style = HashTable{String,Any}() + style = Dict{String,Any}() style["texthalign"] = halign style["textvalign"] = valign for (k,v) in getattr(self, "ticklabels_style") @@ -1620,12 +1620,12 @@ end # PlotComposite --------------------------------------------------------------- type PlotComposite <: HasStyle - attr::HashTable + attr::Dict components::List dont_clip::Bool function PlotComposite(args...) - self = new(HashTable(), {}, false) + self = new(Dict(), {}, false) kw_init(self, args...) self end @@ -1786,7 +1786,7 @@ type FramedPlot <: PlotContainer y2 = HalfAxisY() setattr(y2, "draw_ticklabels", nothing) self = new( - HashTable(), + Dict(), PlotComposite(), PlotComposite(), x1, y1, x2, y2, @@ -1961,7 +1961,7 @@ type Table <: PlotContainer modified function Table( rows, cols, args... ) - self = new(HashTable()) + self = new(Dict()) conf_setattr(self, args... ) self.rows = rows self.cols = cols @@ -2026,7 +2026,7 @@ type Plot <: PlotContainer content function Plot( args... ) - self = new(HashTable()) + self = new(Dict()) conf_setattr(self, args... ) self.content = PlotComposite() self @@ -2100,7 +2100,7 @@ type FramedArray <: PlotContainer content function FramedArray( nrows, ncols, args... ) - self = new(HashTable()) + self = new(Dict()) self.nrows = nrows self.ncols = ncols self.content = cell(nrows, ncols) @@ -2401,7 +2401,7 @@ function compose_interior( self::PlotContainer, device::Renderer, int_bbox::Boun ext_bbox = exterior( self, device, int_bbox ) x = center(int_bbox)[1] y = yrange(ext_bbox)[2] + offset - style = HashTable() + style = Dict() for (k,v) in getattr(self, "title_style") style[k] = v end @@ -2517,12 +2517,12 @@ function make_key( self::LineComponent, bbox::BoundingBox ) end type Curve <: LineComponent - attr::HashTable + attr::Dict x y function Curve(x, y, args...) - attr = HashTable() + attr = Dict() self = new(attr, x, y) iniattr(self) kw_init(self, args2hashtable(args...)...) @@ -2547,13 +2547,13 @@ function make( self::Curve, context ) end type Slope <: LineComponent - attr::HashTable + attr::Dict slope::Real intercept function Slope( slope, intercept, args... ) #LineComponent.__init__( self ) - self = new(HashTable()) + self = new(Dict()) conf_setattr(self) kw_init(self, args...) self.slope = slope @@ -2608,7 +2608,7 @@ type Histogram <: LineComponent binsize function Histogram( values, binsize, args... ) - self = new(HashTable()) + self = new(Dict()) conf_setattr(self) kw_init(self, args...) self.values = values @@ -2661,7 +2661,7 @@ type LineX <: LineComponent x function LineX( x, args... ) - self = new(HashTable()) + self = new(Dict()) conf_setattr(self) kw_init(self, args...) self.x = x @@ -2685,7 +2685,7 @@ type LineY <: LineComponent y function LineY( y, args... ) - self = new(HashTable()) + self = new(Dict()) conf_setattr(self) kw_init(self, args...) self.y = y @@ -2713,7 +2713,7 @@ type BoxLabel <: PlotComponent function BoxLabel( obj, str::String, side, offset, args... ) @assert str != nothing - self = new(HashTable(), obj, str, side, offset) + self = new(Dict(), obj, str, side, offset) kw_init(self, args...) self end @@ -2768,7 +2768,7 @@ type DataLabel <: LabelComponent str function DataLabel( x, y, str, args... ) - self = new(HashTable()) + self = new(Dict()) conf_setattr(self) kw_init(self, args...) self.pos = x, y @@ -2789,7 +2789,7 @@ type PlotLabel <: LabelComponent str function PlotLabel( x, y, str, args... ) - self = new(HashTable()) + self = new(Dict()) conf_setattr(self) kw_init(self, args...) self.pos = x, y @@ -2860,7 +2860,7 @@ type FillAbove <: FillComponent y function __init__( self, x, y, args...) - self = new(HashTable()) + self = new(Dict()) conf_setattr(self) kw_init(self, args...) self.x = x @@ -2889,7 +2889,7 @@ type FillBelow <: FillComponent y function FillBelow( x, y, args...) - self = new(HashTable()) + self = new(Dict()) conf_setattr(self) kw_init(self, args...) self.x = x @@ -2920,7 +2920,7 @@ type FillBetween <: FillComponent y2 function FillBetween(x1, y1, x2, y2, args...) - self = new(HashTable()) + self = new(Dict()) conf_setattr(self) kw_init(self, args...) self.x1 = x1 @@ -2966,7 +2966,7 @@ type Points <: SymbolDataComponent y function Points( x, y, args... ) - self = new(HashTable()) + self = new(Dict()) conf_setattr(self) kw_init(self, args...) self.x = x @@ -3002,7 +3002,7 @@ type ColoredPoints <: SymbolDataComponent c function ColoredPoints( x, y, c, args... ) - self = new(HashTable()) + self = new(Dict()) conf_setattr(self) kw_init(self, args...) self.x = x @@ -3066,7 +3066,7 @@ end # HasAttr --------------------------------------------------------------------- -_attr_map(::HasAttr) = HashTable() +_attr_map(::HasAttr) = Dict() function hasattr(self::HasAttr, name) key = get(_attr_map(self), name, name) @@ -3108,12 +3108,12 @@ const conf_setattr = iniattr # HasStyle --------------------------------------------------------------- -kw_defaults(x) = HashTable() -_kw_rename(x) = HashTable{String,String}() +kw_defaults(x) = Dict() +_kw_rename(x) = Dict{String,String}() function kw_init( self::HasStyle, args...) # jeez, what a mess... - sty = HashTable() + sty = Dict() for (k,v) in kw_defaults(self) sty[k] = v end diff --git a/src/dump.c b/src/dump.c index 9a3335ee13d0d..24a667d413254 100644 --- a/src/dump.c +++ b/src/dump.c @@ -28,7 +28,7 @@ static ptrint_t VALUE_TAGS; // pointers to non-AST-ish objects in a compressed tree static jl_array_t *tree_literal_values=NULL; -// queue of IdTables to rehash +// queue of ObjectIdDicts to rehash static jl_array_t *idtable_list=NULL; static jl_value_t *jl_idtable_type=NULL; void jl_idtable_rehash(jl_array_t **pa, size_t newsz); @@ -751,7 +751,7 @@ void jl_save_system_image(char *fname, char *startscriptname) mt->defs->func->linfo->specializations = NULL; } - jl_idtable_type = jl_get_global(jl_base_module, jl_symbol("IdTable")); + jl_idtable_type = jl_get_global(jl_base_module, jl_symbol("ObjectIdDict")); idtable_list = jl_alloc_cell_1d(0); jl_serialize_value(&f, jl_array_type->env); @@ -805,7 +805,7 @@ void jl_restore_system_image(char *fname) jl_symbol("Base")); jl_array_t *idtl = (jl_array_t*)jl_deserialize_value(&f); - // rehash IdTables + // rehash ObjectIdDicts for(int i=0; i < idtl->length; i++) { jl_value_t *v = jl_cellref(idtl, i); jl_idtable_rehash(&((jl_array_t**)v)[1], diff --git a/test/corelib.jl b/test/corelib.jl index ebdbac9ea7db4..56c0ed1832a4e 100644 --- a/test/corelib.jl +++ b/test/corelib.jl @@ -41,7 +41,7 @@ end @assert (10.^[-1.])[1] == 0.1 # hash table -h = HashTable() +h = Dict() for i=1:10000 h[i] = i+1 end @@ -80,7 +80,7 @@ for i=10000:20000 end let - z = HashTable() + z = Dict() get_KeyError = false try z["a"]