File tree Expand file tree Collapse file tree 1 file changed +18
-7
lines changed Expand file tree Collapse file tree 1 file changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -382,15 +382,26 @@ false
382
382
```
383
383
"""
384
384
function allunique (C)
385
- seen = Set {eltype(C)} ()
386
- for x in C
387
- if in (x, seen)
388
- return false
389
- else
390
- push! (seen, x)
385
+ seen = Dict {eltype(C), Nothing} ()
386
+ x = iterate (C)
387
+ if haslength (C) && length (C) > 1000
388
+ for i in OneTo (1000 )
389
+ v, s = x
390
+ idx = ht_keyindex2! (seen, v)
391
+ idx > 0 && return false
392
+ _setindex! (seen, nothing , v, - idx)
393
+ x = iterate (C, s)
391
394
end
395
+ sizehint! (seen, length (C))
396
+ end
397
+ while x != = nothing
398
+ v, s = x
399
+ idx = ht_keyindex2! (seen, v)
400
+ idx > 0 && return false
401
+ _setindex! (seen, nothing , v, - idx)
402
+ x = iterate (C, s)
392
403
end
393
- true
404
+ return true
394
405
end
395
406
396
407
allunique (:: Union{AbstractSet,AbstractDict} ) = true
You can’t perform that action at this time.
0 commit comments