| function | since v0.0-927 | Edit |
(intersection s1)(intersection s1 s2)(intersection s1 s2 & sets)Return a set that is the intersection of the input sets.
Return a set that is the intersection of the input sets
(defn intersection
([s1] s1)
([s1 s2]
(if (< (count s2) (count s1))
(recur s2 s1)
(reduce (fn [result item]
(if (contains? s2 item)
result
(disj result item)))
s1 s1)))
([s1 s2 & sets]
(let [bubbled-sets (bubble-max-key #(- (count %)) (conj sets s2 s1))]
(reduce intersection (first bubbled-sets) (rest bubbled-sets)))))