Project

General

Profile

Actions

Feature #15976

closed

Add Array#overlap? for whether the intersection of 2 arrays is non empty?

Added by fcheung (Frederick Cheung) over 5 years ago. Updated over 3 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:93487]

Description

This is semantically equivalent to (ary1 & ary2).any?, but more efficient and makes the intent more obvious.

For example bundler checks whether the list of requested groups and the list of groups for a dependency has any overlap - it doesn't care what the overlap is, as long as it is non empty

In my personal projects we've found this to be a bottleneck when the arrays are large and where intersections are likely - !(ary1 & ary2).empty? keeps searching for all of the intersection even after we've found the first one, & creates extra garbage because of the intermediate array.

See https://github.com/ruby/ruby/pull/2260


Files

2260.patch (7.9 KB) 2260.patch fcheung (Frederick Cheung), 07/02/2019 09:02 PM

Related issues 2 (0 open2 closed)

Related to Ruby master - Feature #19839: Need a method to check if two ranges overlapClosedActions
Is duplicate of Ruby master - Feature #15198: Array#intersect?Closedmatz (Yukihiro Matsumoto)Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0