Skip to content

Commit

Permalink
improve speed of allunique (JuliaLang#37208)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkamins authored Aug 27, 2020
1 parent 701885b commit f8a73da
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions base/set.jl
Original file line number Diff line number Diff line change
Expand Up @@ -382,15 +382,26 @@ false
```
"""
function allunique(C)
seen = Set{eltype(C)}()
for x in C
if in(x, seen)
return false
else
push!(seen, x)
seen = Dict{eltype(C), Nothing}()
x = iterate(C)
if haslength(C) && length(C) > 1000
for i in OneTo(1000)
v, s = x
idx = ht_keyindex2!(seen, v)
idx > 0 && return false
_setindex!(seen, nothing, v, -idx)
x = iterate(C, s)
end
sizehint!(seen, length(C))
end
while x !== nothing
v, s = x
idx = ht_keyindex2!(seen, v)
idx > 0 && return false
_setindex!(seen, nothing, v, -idx)
x = iterate(C, s)
end
true
return true
end

allunique(::Union{AbstractSet,AbstractDict}) = true
Expand Down

0 comments on commit f8a73da

Please sign in to comment.