Skip to content

Commit ccf9ab5

Browse files
committed
changes because of using instead of import
1 parent 954b55d commit ccf9ab5

File tree

1 file changed

+28
-30
lines changed

1 file changed

+28
-30
lines changed

src/swiss_dict.jl

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,20 @@ function SwissDict{K,V}(ps::Pair...) where {K, V}
6464
end
6565
SwissDict() = SwissDict{Any,Any}()
6666
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}()
6969

7070
SwissDict(ps::Pair{K,V}...) where {K,V} = SwissDict{K,V}(ps)
7171
SwissDict(ps::Pair...) = SwissDict(ps)
7272

7373
function SwissDict(kv)
7474
try
7575
dict_with_eltype((K, V) -> SwissDict{K, V}, kv, eltype(kv))
76-
catch
76+
catch e
7777
if !isiterable(typeof(kv)) || !all(x->isa(x,Union{Tuple,Pair}),kv)
7878
throw(ArgumentError("SwissDict(kv): kv needs to be an iterator of tuples or pairs"))
7979
else
80-
rethrow()
80+
rethrow(e)
8181
end
8282
end
8383
end
@@ -274,7 +274,7 @@ function maybe_rehash_shrink!(h::SwissDict)
274274
end
275275
end
276276

277-
function sizehint!(d::SwissDict, newsz)
277+
function Base.sizehint!(d::SwissDict, newsz)
278278
newsz = _tablesz(newsz*2) # *2 for keys and values in same array
279279
oldsz = length(d.keys)
280280
# grow at least 25%
@@ -366,7 +366,7 @@ julia> A
366366
SwissDict{String,Int64} with 0 entries
367367
```
368368
"""
369-
function empty!(h::SwissDict{K,V}) where {K, V}
369+
function Base.empty!(h::SwissDict{K,V}) where {K, V}
370370
fill!(h.slots, _expand16(0x00))
371371
sz = length(h.keys)
372372
empty!(h.keys)
@@ -380,7 +380,7 @@ function empty!(h::SwissDict{K,V}) where {K, V}
380380
return h
381381
end
382382

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}
384384
key = convert(K, key0)
385385
_setindex!(h, v0, key)
386386
end
@@ -424,7 +424,7 @@ SwissDict{String,Int64} with 4 entries:
424424
"d" => 4
425425
```
426426
"""
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)
428428

429429
"""
430430
get!(f::Function, collection, key)
@@ -440,7 +440,7 @@ get!(dict, key) do
440440
end
441441
```
442442
"""
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}
444444
key = convert(K, key0)
445445
return _get!(default, h, key)
446446
end
@@ -465,7 +465,7 @@ function _get!(default::Callable, h::SwissDict{K,V}, key::K) where {K, V}
465465
return v
466466
end
467467

468-
function getindex(h::SwissDict{K,V}, key) where {K, V}
468+
function Base.getindex(h::SwissDict{K,V}, key) where {K, V}
469469
index = ht_keyindex(h, key)
470470
@inbounds return (index < 0) ? throw(KeyError(key)) : h.vals[index]::V
471471
end
@@ -487,7 +487,7 @@ julia> get(d, "c", 3)
487487
3
488488
```
489489
"""
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}
491491
index = ht_keyindex(h, key)
492492
@inbounds return (index < 0) ? default : h.vals[index]::V
493493
end
@@ -507,7 +507,7 @@ get(dict, key) do
507507
end
508508
```
509509
"""
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}
511511
index = ht_keyindex(h, key)
512512
@inbounds return (index < 0) ? default() : h.vals[index]::V
513513
end
@@ -531,8 +531,8 @@ julia> haskey(D, 'c')
531531
false
532532
```
533533
"""
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)
536536

537537
"""
538538
getkey(collection, key, default)
@@ -553,11 +553,18 @@ julia> getkey(D, 'd', 'a')
553553
'a': ASCII/Unicode U+0061 (category Ll: Letter, lowercase)
554554
```
555555
"""
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}
557557
index = ht_keyindex(h, key)
558558
@inbounds return (index<0) ? default : h.keys[index]::K
559559
end
560560

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+
561568
"""
562569
pop!(collection, key[, default])
563570
@@ -580,26 +587,17 @@ julia> pop!(d, "e", 4)
580587
4
581588
```
582589
"""
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)
593591
index = ht_keyindex(h, key)
594592
return index > 0 ? _pop!(h, index) : throw(KeyError(key))
595593
end
596594

597-
function pop!(h::SwissDict, key, default)
595+
function Base.pop!(h::SwissDict, key, default)
598596
index = ht_keyindex(h, key)
599597
return index > 0 ? _pop!(h, index) : default
600598
end
601599

602-
function pop!(h::SwissDict)
600+
function Base.pop!(h::SwissDict)
603601
isempty(h) && throw(ArgumentError("SwissDict must be non-empty"))
604602
is = _iterslots(h, h.idxfloor)
605603
@assert is !== nothing
@@ -628,7 +626,7 @@ SwissDict{String,Int64} with 1 entry:
628626
"a" => 1
629627
```
630628
"""
631-
function delete!(h::SwissDict, key)
629+
function Base.delete!(h::SwissDict, key)
632630
index = ht_keyindex(h, key)
633631
if index > 0
634632
_delete!(h, index)
@@ -637,15 +635,15 @@ function delete!(h::SwissDict, key)
637635
return h
638636
end
639637

640-
Base.@propagate_inbounds function iterate(h::SwissDict, state = h.idxfloor)
638+
Base.@propagate_inbounds function Base.iterate(h::SwissDict, state = h.idxfloor)
641639
is = _iterslots(h, state)
642640
is === nothing && return nothing
643641
i, s = is
644642
@inbounds p = h.keys[i] => h.vals[i]
645643
return (p, s)
646644
end
647645

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)
649647
is = _iterslots(v.dict, state)
650648
is === nothing && return nothing
651649
i, s = is

0 commit comments

Comments
 (0)