@@ -146,6 +146,14 @@ Set{Float64} with 1 element:
146146```
147147"""
148148function intersect (s:: AbstractSet , itr, itrs... )
149+ # heuristics to try to `intersect` with the shortest Set on the left
150+ if length (s)> 50 && haslength (itr) && all (haslength, itrs)
151+ min_length, min_idx = findmin (length, itrs)
152+ if length (itr) > min_length
153+ new_itrs = setindex (itrs, itr, min_idx)
154+ return intersect (s, itrs[min_idx], new_itrs... )
155+ end
156+ end
149157 T = promote_eltype (s, itr, itrs... )
150158 if T == promote_eltype (s, itr)
151159 out = intersect (s, itr)
@@ -156,7 +164,13 @@ function intersect(s::AbstractSet, itr, itrs...)
156164 return intersect! (out, itrs... )
157165end
158166intersect (s) = union (s)
159- intersect (s:: AbstractSet , itr) = mapfilter (in (s), push!, itr, emptymutable (s, promote_eltype (s, itr)))
167+ function intersect (s:: AbstractSet , itr)
168+ if haslength (itr) && hasfastin (itr) && length (s) < length (itr)
169+ return mapfilter (in (itr), push!, s, emptymutable (s, promote_eltype (s, itr)))
170+ else
171+ return mapfilter (in (s), push!, itr, emptymutable (s, promote_eltype (s, itr)))
172+ end
173+ end
160174
161175const ∩ = intersect
162176
0 commit comments