@@ -64,20 +64,20 @@ function SwissDict{K,V}(ps::Pair...) where {K, V}
64
64
end
65
65
SwissDict () = SwissDict {Any,Any} ()
66
66
SwissDict (kv:: Tuple{} ) = SwissDict ()
67
- copy (d:: SwissDict ) = SwissDict (d)
68
- empty (d:: SwissDict , :: Type{K} , :: Type{V} ) where {K, V} = SwissDict {K, V} ()
67
+ Base . copy (d:: SwissDict ) = SwissDict (d)
68
+ Base . empty (d:: SwissDict , :: Type{K} , :: Type{V} ) where {K, V} = SwissDict {K, V} ()
69
69
70
70
SwissDict (ps:: Pair{K,V} ...) where {K,V} = SwissDict {K,V} (ps)
71
71
SwissDict (ps:: Pair... ) = SwissDict (ps)
72
72
73
73
function SwissDict (kv)
74
74
try
75
75
dict_with_eltype ((K, V) -> SwissDict{K, V}, kv, eltype (kv))
76
- catch
76
+ catch e
77
77
if ! isiterable (typeof (kv)) || ! all (x-> isa (x,Union{Tuple,Pair}),kv)
78
78
throw (ArgumentError (" SwissDict(kv): kv needs to be an iterator of tuples or pairs" ))
79
79
else
80
- rethrow ()
80
+ rethrow (e )
81
81
end
82
82
end
83
83
end
@@ -274,7 +274,7 @@ function maybe_rehash_shrink!(h::SwissDict)
274
274
end
275
275
end
276
276
277
- function sizehint! (d:: SwissDict , newsz)
277
+ function Base . sizehint! (d:: SwissDict , newsz)
278
278
newsz = _tablesz (newsz* 2 ) # *2 for keys and values in same array
279
279
oldsz = length (d. keys)
280
280
# grow at least 25%
@@ -366,7 +366,7 @@ julia> A
366
366
SwissDict{String,Int64} with 0 entries
367
367
```
368
368
"""
369
- function empty! (h:: SwissDict{K,V} ) where {K, V}
369
+ function Base . empty! (h:: SwissDict{K,V} ) where {K, V}
370
370
fill! (h. slots, _expand16 (0x00 ))
371
371
sz = length (h. keys)
372
372
empty! (h. keys)
@@ -380,7 +380,7 @@ function empty!(h::SwissDict{K,V}) where {K, V}
380
380
return h
381
381
end
382
382
383
- function setindex! (h:: SwissDict{K,V} , v0, key0) where {K, V}
383
+ function Base . setindex! (h:: SwissDict{K,V} , v0, key0) where {K, V}
384
384
key = convert (K, key0)
385
385
_setindex! (h, v0, key)
386
386
end
@@ -424,7 +424,7 @@ SwissDict{String,Int64} with 4 entries:
424
424
"d" => 4
425
425
```
426
426
"""
427
- get! (h:: SwissDict{K,V} , key0, default) where {K,V} = get! (()-> default, h, key0)
427
+ Base . get! (h:: SwissDict{K,V} , key0, default) where {K,V} = get! (()-> default, h, key0)
428
428
429
429
"""
430
430
get!(f::Function, collection, key)
@@ -440,7 +440,7 @@ get!(dict, key) do
440
440
end
441
441
```
442
442
"""
443
- function get! (default:: Callable , h:: SwissDict{K,V} , key0) where {K, V}
443
+ function Base . get! (default:: Callable , h:: SwissDict{K,V} , key0) where {K, V}
444
444
key = convert (K, key0)
445
445
return _get! (default, h, key)
446
446
end
@@ -465,7 +465,7 @@ function _get!(default::Callable, h::SwissDict{K,V}, key::K) where {K, V}
465
465
return v
466
466
end
467
467
468
- function getindex (h:: SwissDict{K,V} , key) where {K, V}
468
+ function Base . getindex (h:: SwissDict{K,V} , key) where {K, V}
469
469
index = ht_keyindex (h, key)
470
470
@inbounds return (index < 0 ) ? throw (KeyError (key)) : h. vals[index]:: V
471
471
end
@@ -487,7 +487,7 @@ julia> get(d, "c", 3)
487
487
3
488
488
```
489
489
"""
490
- function get (h:: SwissDict{K,V} , key, default) where {K, V}
490
+ function Base . get (h:: SwissDict{K,V} , key, default) where {K, V}
491
491
index = ht_keyindex (h, key)
492
492
@inbounds return (index < 0 ) ? default : h. vals[index]:: V
493
493
end
@@ -507,7 +507,7 @@ get(dict, key) do
507
507
end
508
508
```
509
509
"""
510
- function get (default:: Callable , h:: SwissDict{K,V} , key) where {K, V}
510
+ function Base . get (default:: Callable , h:: SwissDict{K,V} , key) where {K, V}
511
511
index = ht_keyindex (h, key)
512
512
@inbounds return (index < 0 ) ? default () : h. vals[index]:: V
513
513
end
@@ -531,8 +531,8 @@ julia> haskey(D, 'c')
531
531
false
532
532
```
533
533
"""
534
- haskey (h:: SwissDict , key) = (ht_keyindex (h, key) > 0 )
535
- in (key, v:: KeySet{<:Any, <:SwissDict} ) = (ht_keyindex (v. dict, key) > 0 )
534
+ Base . haskey (h:: SwissDict , key) = (ht_keyindex (h, key) > 0 )
535
+ Base . in (key, v:: KeySet{<:Any, <:SwissDict} ) = (ht_keyindex (v. dict, key) > 0 )
536
536
537
537
"""
538
538
getkey(collection, key, default)
@@ -553,11 +553,18 @@ julia> getkey(D, 'd', 'a')
553
553
'a': ASCII/Unicode U+0061 (category Ll: Letter, lowercase)
554
554
```
555
555
"""
556
- function getkey (h:: SwissDict{K,V} , key, default) where {K, V}
556
+ function Base . getkey (h:: SwissDict{K,V} , key, default) where {K, V}
557
557
index = ht_keyindex (h, key)
558
558
@inbounds return (index< 0 ) ? default : h. keys[index]:: K
559
559
end
560
560
561
+ function _pop! (h:: SwissDict , index)
562
+ @inbounds val = h. vals[index]
563
+ _delete! (h, index)
564
+ maybe_rehash_shrink! (h)
565
+ return val
566
+ end
567
+
561
568
"""
562
569
pop!(collection, key[, default])
563
570
@@ -580,26 +587,17 @@ julia> pop!(d, "e", 4)
580
587
4
581
588
```
582
589
"""
583
- pop! (collection, key, default)
584
-
585
- function _pop! (h:: SwissDict , index)
586
- @inbounds val = h. vals[index]
587
- _delete! (h, index)
588
- maybe_rehash_shrink! (h)
589
- return val
590
- end
591
-
592
- function pop! (h:: SwissDict , key)
590
+ function Base. pop! (h:: SwissDict , key)
593
591
index = ht_keyindex (h, key)
594
592
return index > 0 ? _pop! (h, index) : throw (KeyError (key))
595
593
end
596
594
597
- function pop! (h:: SwissDict , key, default)
595
+ function Base . pop! (h:: SwissDict , key, default)
598
596
index = ht_keyindex (h, key)
599
597
return index > 0 ? _pop! (h, index) : default
600
598
end
601
599
602
- function pop! (h:: SwissDict )
600
+ function Base . pop! (h:: SwissDict )
603
601
isempty (h) && throw (ArgumentError (" SwissDict must be non-empty" ))
604
602
is = _iterslots (h, h. idxfloor)
605
603
@assert is != = nothing
@@ -628,7 +626,7 @@ SwissDict{String,Int64} with 1 entry:
628
626
"a" => 1
629
627
```
630
628
"""
631
- function delete! (h:: SwissDict , key)
629
+ function Base . delete! (h:: SwissDict , key)
632
630
index = ht_keyindex (h, key)
633
631
if index > 0
634
632
_delete! (h, index)
@@ -637,15 +635,15 @@ function delete!(h::SwissDict, key)
637
635
return h
638
636
end
639
637
640
- Base. @propagate_inbounds function iterate (h:: SwissDict , state = h. idxfloor)
638
+ Base. @propagate_inbounds function Base . iterate (h:: SwissDict , state = h. idxfloor)
641
639
is = _iterslots (h, state)
642
640
is === nothing && return nothing
643
641
i, s = is
644
642
@inbounds p = h. keys[i] => h. vals[i]
645
643
return (p, s)
646
644
end
647
645
648
- Base. @propagate_inbounds function iterate (v:: Union{KeySet{<:Any, <:SwissDict}, Base.ValueIterator{<:SwissDict}} , state= v. dict. idxfloor)
646
+ Base. @propagate_inbounds function Base . iterate (v:: Union{KeySet{<:Any, <:SwissDict}, Base.ValueIterator{<:SwissDict}} , state= v. dict. idxfloor)
649
647
is = _iterslots (v. dict, state)
650
648
is === nothing && return nothing
651
649
i, s = is
0 commit comments