JuliaLang/julia

issetequal between ranges and other collections

Open

#35,182 opened on Mar 20, 2020

View on GitHub
 (0 comments) (0 reactions) (0 assignees)Julia (5,773 forks)batch import
collectionsequalityhelp wantedperformance

Repository metrics

Stars
 (48,709 stars)
PR merge metrics
 (Avg merge 20d 6h) (157 merged PRs in 30d)

Description

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()

Contributor guide