@@ -99,27 +99,11 @@ type Dict{K,V} <: Associative{K,V}
99
99
idxfloor:: Int # an index <= the indexes of all used slots
100
100
maxprobe:: Int
101
101
102
- function Dict ()
102
+ function Dict {K,V} () where V where K
103
103
n = 16
104
104
new (zeros (UInt8,n), Array {K,1} (n), Array {V,1} (n), 0 , 0 , 0 , 1 , 0 )
105
105
end
106
- function Dict (kv)
107
- h = Dict {K,V} ()
108
- for (k,v) in kv
109
- h[k] = v
110
- end
111
- return h
112
- end
113
- Dict (p:: Pair ) = setindex! (Dict {K,V} (), p. second, p. first)
114
- function Dict (ps:: Pair... )
115
- h = Dict {K,V} ()
116
- sizehint! (h, length (ps))
117
- for p in ps
118
- h[p. first] = p. second
119
- end
120
- return h
121
- end
122
- function Dict (d:: Dict{K,V} )
106
+ function Dict {K,V} (d:: Dict{K,V} ) where V where K
123
107
if d. ndel > 0
124
108
rehash! (d)
125
109
end
@@ -128,17 +112,33 @@ type Dict{K,V} <: Associative{K,V}
128
112
d. maxprobe)
129
113
end
130
114
end
115
+ function Dict {K,V} (kv) where V where K
116
+ h = Dict {K,V} ()
117
+ for (k,v) in kv
118
+ h[k] = v
119
+ end
120
+ return h
121
+ end
122
+ Dict {K,V} (p:: Pair ) where V where K = setindex! (Dict {K,V} (), p. second, p. first)
123
+ function Dict {K,V} (ps:: Pair... ) where V where K
124
+ h = Dict {K,V} ()
125
+ sizehint! (h, length (ps))
126
+ for p in ps
127
+ h[p. first] = p. second
128
+ end
129
+ return h
130
+ end
131
131
# Note the constructors of WeakKeyDict mirror these here, keep in sync.
132
132
Dict () = Dict {Any,Any} ()
133
133
Dict (kv:: Tuple{} ) = Dict ()
134
134
copy (d:: Dict ) = Dict (d)
135
135
136
136
const AnyDict = Dict{Any,Any}
137
137
138
- Dict {K,V} (ps:: Pair{K,V} ...) = Dict {K,V} (ps)
139
- Dict {K } (ps:: Pair{K} ...,) = Dict {K,Any} (ps)
140
- Dict {V } (ps:: (Pair{K,V} where K) ...,) = Dict {Any,V} (ps)
141
- Dict ( ps:: Pair... ) = Dict {Any,Any} (ps)
138
+ Dict (ps:: Pair{K,V} ...) where {K,V} = Dict {K,V} (ps)
139
+ Dict (ps:: Pair{K} ...,) where K = Dict {K,Any} (ps)
140
+ Dict (ps:: (Pair{K,V} where K) ...,) where V = Dict {Any,V} (ps)
141
+ Dict (ps:: Pair... ) = Dict {Any,Any} (ps)
142
142
143
143
function Dict (kv)
144
144
try
@@ -599,9 +599,9 @@ immutable ImmutableDict{K, V} <: Associative{K,V}
599
599
parent:: ImmutableDict{K, V}
600
600
key:: K
601
601
value:: V
602
- ImmutableDict () = new () # represents an empty dictionary
603
- ImmutableDict (key, value) = (empty = new (); new (empty, key, value))
604
- ImmutableDict (parent:: ImmutableDict , key, value) = new (parent, key, value)
602
+ ImmutableDict {K,V} () where {K,V} = new () # represents an empty dictionary
603
+ ImmutableDict {K,V} (key, value) where {K,V} = (empty = new (); new (empty, key, value))
604
+ ImmutableDict {K,V} (parent:: ImmutableDict , key, value) where {K,V} = new (parent, key, value)
605
605
end
606
606
607
607
"""
@@ -621,8 +621,8 @@ Create a new entry in the Immutable Dictionary for the key => value pair
621
621
622
622
"""
623
623
ImmutableDict
624
- ImmutableDict {K,V} (KV:: Pair{K,V} ) = ImmutableDict {K,V} (KV[1 ], KV[2 ])
625
- ImmutableDict {K,V} (t:: ImmutableDict{K,V} , KV:: Pair ) = ImmutableDict {K,V} (t, KV[1 ], KV[2 ])
624
+ ImmutableDict (KV:: Pair{K,V} ) where {K,V} = ImmutableDict {K,V} (KV[1 ], KV[2 ])
625
+ ImmutableDict (t:: ImmutableDict{K,V} , KV:: Pair ) where {K,V} = ImmutableDict {K,V} (t, KV[1 ], KV[2 ])
626
626
627
627
function in (key_value:: Pair , dict:: ImmutableDict , valcmp= (== ))
628
628
key, value = key_value
0 commit comments