JuliaLang/julia

issetequal between ranges and other collections

Open

#35.182 aperta il 20 mar 2020

Vedi su GitHub
 (0 commenti) (0 reazioni) (0 assegnatari)Julia (5773 fork)batch import
collectionsequalityhelp wantedperformance

Metriche repository

Star
 (48.709 star)
Metriche merge PR
 (Merge medio 20g 6h) (157 PR mergiate in 30 g)

Descrizione

Looking at the following benchmarks issetequal is the equal slowest way to accomplish this

julia> data = shuffle(1:1000);

julia> @btime Set($data)==Set(1:1000);
  41.753 μs (24 allocations: 91.92 KiB)

julia> @btime isempty(setdiff($data, 1:1000));
  29.072 μs (15 allocations: 53.95 KiB)

julia> @btime (k = Set($data); length(k)==1000 && extrema(k) ==(1,1000))
  18.206 μs (12 allocations: 45.96 KiB)

julia> @btime issetequal($data, 1:1000);
  41.458 μs (24 allocations: 91.92 KiB)

It would be a nice PR to add some more overloads like that. I suspect the extrema + length is good for all types that IteratorSize(T) = HasLength()

Guida contributor