1
- import Base: setindex!, sizehint!, empty!, isempty, length, copy, empty,
2
- getindex, getkey, haskey, iterate, @propagate_inbounds , ValueIterator,
3
- pop!, delete!, get, get!, isbitstype, in, hashindex, isbitsunion,
4
- isiterable, dict_with_eltype, KeySet, Callable, _tablesz, filter!
5
-
6
1
const SWISS_DICT_LOAD_FACTOR = 0.75
7
2
const _u8x16 = NTuple{16 , VecElement{UInt8}}
8
3
101
96
return (hi, tag)
102
97
end
103
98
104
- @propagate_inbounds function _slotget (slots:: Vector{_u8x16} , i:: Int )
99
+ Base . @propagate_inbounds function _slotget (slots:: Vector{_u8x16} , i:: Int )
105
100
@boundscheck 0 < i <= length (slots)* 16 || throw (BoundsError (slots, 1 + (i- 1 )>> 4 ))
106
101
GC. @preserve slots begin
107
102
return unsafe_load (convert (Ptr{UInt8}, pointer (slots)), i)
108
103
end
109
104
end
110
105
111
- @propagate_inbounds function _slotset! (slots:: Vector{_u8x16} , v:: UInt8 , i:: Int )
106
+ Base . @propagate_inbounds function _slotset! (slots:: Vector{_u8x16} , v:: UInt8 , i:: Int )
112
107
@boundscheck 0 < i <= length (slots)* 16 || throw (BoundsError (slots, 1 + (i- 1 )>> 4 ))
113
108
GC. @preserve slots begin
114
109
return unsafe_store! (convert (Ptr{UInt8}, pointer (slots)), v, i)
@@ -201,7 +196,7 @@ function _setindex!(h::SwissDict, v, key, index, tag)
201
196
end
202
197
203
198
function _delete! (h:: SwissDict{K,V} , index) where {K,V}
204
- # Caller is responsible for maybe shrinking the SwissDict after the deletion.
199
+ # Caller is responsible for maybe shrinking the SwissDict after the deletion.
205
200
isbitstype (K) || isbitsunion (K) || ccall (:jl_arrayunset , Cvoid, (Any, UInt), h. keys, index- 1 )
206
201
isbitstype (V) || isbitsunion (V) || ccall (:jl_arrayunset , Cvoid, (Any, UInt), h. vals, index- 1 )
207
202
isboundary = iszero (index & 0x0f ) # boundaries: 16, 32, ...
@@ -212,7 +207,7 @@ function _delete!(h::SwissDict{K,V}, index) where {K,V}
212
207
end
213
208
214
209
215
- # fast iteration over active slots.
210
+ # fast iteration over active slots.
216
211
function _iterslots (h:: SwissDict , start:: Int )
217
212
i0 = ((start- 1 ) & (length (h. keys)- 1 ))>> 4 + 1
218
213
off = (start- 1 ) & 0x0f
@@ -232,13 +227,13 @@ function _iterslots(h::SwissDict, state)
232
227
return ((i- 1 )* 16 + trailing_zeros (sl) + 1 , (i, _blsr (sl)))
233
228
end
234
229
235
- # Dictionary resize logic:
236
- # Guarantee 40% of buckets and 15% of entries free, and at least 25% of entries filled
237
- # growth when > 85% entries full or > 60% buckets full, shrink when <25% entries full.
238
- # >60% bucket full should be super rare outside of very bad hash collisions or
239
- # super long-lived Dictionaries (expected 0.85^16 = 7% buckets full at 85% entries full).
240
- # worst-case hysteresis: shrink at 25% vs grow at 30% if all hashes collide.
241
- # expected hysteresis is 25% to 42.5%.
230
+ # Dictionary resize logic:
231
+ # Guarantee 40% of buckets and 15% of entries free, and at least 25% of entries filled
232
+ # growth when > 85% entries full or > 60% buckets full, shrink when <25% entries full.
233
+ # >60% bucket full should be super rare outside of very bad hash collisions or
234
+ # super long-lived Dictionaries (expected 0.85^16 = 7% buckets full at 85% entries full).
235
+ # worst-case hysteresis: shrink at 25% vs grow at 30% if all hashes collide.
236
+ # expected hysteresis is 25% to 42.5%.
242
237
function maybe_rehash_grow! (h:: SwissDict )
243
238
sz = length (h. keys)
244
239
if h. count > sz * SWISS_DICT_LOAD_FACTOR || (h. nbfull- 1 ) * 10 > sz * 6
@@ -459,15 +454,15 @@ function delete!(h::SwissDict, key)
459
454
return h
460
455
end
461
456
462
- @propagate_inbounds function iterate (h:: SwissDict , state = h. idxfloor)
457
+ Base . @propagate_inbounds function iterate (h:: SwissDict , state = h. idxfloor)
463
458
is = _iterslots (h, state)
464
459
is === nothing && return nothing
465
460
i, s = is
466
461
@inbounds p = h. keys[i] => h. vals[i]
467
462
return (p, s)
468
463
end
469
464
470
- @propagate_inbounds function iterate (v:: Union{KeySet{<:Any, <:SwissDict}, ValueIterator{<:SwissDict}} , state= v. dict. idxfloor)
465
+ Base . @propagate_inbounds function iterate (v:: Union{KeySet{<:Any, <:SwissDict}, Base. ValueIterator{<:SwissDict}} , state= v. dict. idxfloor)
471
466
is = _iterslots (v. dict, state)
472
467
is === nothing && return nothing
473
468
i, s = is
0 commit comments