Returns true if there is at least element that is in both s1 and s2. Faster
than calling intersection(Set,Set) if you don't need the contents of the
intersection.
976874
public static <E> boolean intersects(Set<E> s1, Set<E> s2) {
    // loop over whichever set is smaller
    if (s1.size() < s2.size()) {
      for (E element1 : s1) {
        if (s2.contains(element1)) {
          return true;
        }
      }
    } else {
      for (E element2 : s2) {
        if (s1.contains(element2)) {
          return true;
        }
      }
    }
    
    return false;
  }
208520
@Pure
	protected int compareSegments(ST s1, ST s2) {
		assert s1 != null && s2 != null;
		return s1.hashCode() - s2.hashCode();
	}
420503
def intersection_update(self, other):
        
        if not isinstance(other, Set):
            raise ValueError('other must be a Set instance')
        if self is other:
            return
        # we make a copy of the list so that we can remove items from
        # the list without breaking the iterator.
        for item in list(self.items):
            if item not in other.items:
                self.items.remove(item)
287997
public boolean isSuperset(SmallSet<E> other) {
        if (this.list.size() < other.list.size()) {
            return false;
        }
        int j = 0;
        for (int i=0; i<list.size() && j<other.list.size(); i++) {
            E e1 = this.list.get(i);
            E e2 = other.list.get(j);
            int diff = e1.compareTo(e2);
            if (diff == 0) {
                // Equal entries. Just continue.
                j++;
                continue;
            } else if (diff > 0) {
                // e1 is greater than e2, which means e2 must not appear in this.list.
                return false;
            } else {
                // e1 is less than e2, so e2 might appear later in this.list.
                continue;
            }
        }
        if (j == other.list.size()) {
            return true;
        } else {
            return false;
        }
    }
667666
public static <E> Set<E> intersection(Set<E> first, Set<E> second) {
        if (first == null || second == null) {
            return EMPTY_SET;
        }

        Set<E> intersection = new HashSet<>();

        for (E e : first) {
            if (second.contains(e)) {
                intersection.add(e);
            }
        }
        return intersection;
    }
1148867
def intersection(other)
      raise(ISO8601::Errors::IntervalError, "The intervals are disjoint") \
        if disjoint?(other) && other.disjoint?(self)

      return self if subset?(other)
      return other if other.subset?(self)

      a, b = sort_pair(self, other)
      self.class.from_datetimes(b.first, a.last)
    end
779686
def intersection(self, *others):
        
        return self.copy(super(NGram, self).intersection(*others))
878859
function (other) {
        assertNotNull(other);

        var c = collectionCount(other);

        if (c !== -1) {
            if (this.count() === 0) {
                return c > 0;
            }

            // faster if other is a hashset (and we're using same equality comparer)
            else if (areEqualityComparersEqual(this, other)) {
                if (this.count() >= c) {
                    return false;
                }

                // this has strictly less than number of items in other, so the following
                // check suffices for proper subset.
                else {
                    return containsAllElements(other, this);
                }
            }
        }

        var result = checkUniqueAndUnfoundElements(this, other, false);
        return (result.uniqueCount === this.count() && result.unfoundCount > 0);
    }
493534
def intersection(self,other):
        
        if self.bounds[0] < other.bounds[0]:
            i1,i2 = self,other
        else:
            i2,i1 = self,other

        if self.is_disjoint(other):
            return Interval((1,0),(True,True))

        bounds = [None,None]
        included = [None,None]
        #sets are not disjoint, so i2.bounds[0] in i1:
        bounds[0] = i2.bounds[0]
        included[0] = i2.included[0]

        if i2.bounds[1] in i1:
            bounds[1] = i2.bounds[1]
            included[1] = i2.included[1]
        else:
            bounds[1] = i1.bounds[1]
            included[1] = i1.included[1]

        return Interval(bounds,included)
359350
def intersection(other)
      if other.is_a?(RelativeComplement)
        # A ∩ ¬B = ¬B ∩ A
        other.intersection(self)
      elsif other.is_a?(AbstractSet)
        if other.is_a?(RelativeSet) and size > other.size
          # For efficiency, iterate the smaller of the two sets: A ∩ B = B ∩ A
          other.intersection(self)
        elsif other.empty?
          # A ∩ ∅ = ∅
          NullSet.build
        else
          hash = @hash.clone.delete_if{|o,_| not other.include?(o) }

          if hash.empty?
            NullSet.build
          else
            RelativeSet.new(hash)
          end
        end
      else
        intersection(Cantor.build(other))
      end
    end
635955
public static boolean intersects(final RoaringBitmap x1, final RoaringBitmap x2) {
    final int length1 = x1.highLowContainer.size(), length2 = x2.highLowContainer.size();
    int pos1 = 0, pos2 = 0;

    while (pos1 < length1 && pos2 < length2) {
      final short s1 = x1.highLowContainer.getKeyAtIndex(pos1);
      final short s2 = x2.highLowContainer.getKeyAtIndex(pos2);
      if (s1 == s2) {
        final Container c1 = x1.highLowContainer.getContainerAtIndex(pos1);
        final Container c2 = x2.highLowContainer.getContainerAtIndex(pos2);
        if (c1.intersects(c2)) {
          return true;
        }
        ++pos1;
        ++pos2;
      } else if (Util.compareUnsigned(s1, s2) < 0) { // s1 < s2
        pos1 = x1.highLowContainer.advanceUntil(s2, pos1);
      } else { // s1 > s2
        pos2 = x2.highLowContainer.advanceUntil(s1, pos2);
      }
    }
    return false;
  }
367043
public static boolean isEqualOrNull( Map s1,
                                         Map s2 ) {
        if ( s1 == null
                && s2 == null ) {
            return true;
        } else if ( s1 != null
                && s2 != null
                && s1.size() == s2.size() ) {
            return true;
        }
        return false;
    }
75108
public boolean contains(ImmutableRoaringBitmap subset) {
    if(subset.getCardinality() > getCardinality()) {
      return false;
    }
    final int length1 = this.highLowContainer.size();
    final int length2 = subset.highLowContainer.size();
    int pos1 = 0, pos2 = 0;
    while (pos1 < length1 && pos2 < length2) {
      final short s1 = this.highLowContainer.getKeyAtIndex(pos1);
      final short s2 = subset.highLowContainer.getKeyAtIndex(pos2);
      if (s1 == s2) {
        MappeableContainer c1 = this.highLowContainer.getContainerAtIndex(pos1);
        MappeableContainer c2 = subset.highLowContainer.getContainerAtIndex(pos2);
        if(!c1.contains(c2)) {
          return false;
        }
        ++pos1;
        ++pos2;
      } else if (compareUnsigned(s1, s2) > 0) {
        return false;
      } else {
        pos1 = subset.highLowContainer.advanceUntil(s2, pos1);
      }
    }
    return pos2 == length2;
  }
313386
def __matches(s1, s2, ngrams_fn, n=3):
    
    ngrams1, ngrams2 = set(ngrams_fn(s1, n=n)), set(ngrams_fn(s2, n=n))
    return ngrams1.intersection(ngrams2)
1266807
function intersection(sets) {
  let source = sets[0];
  let rest = sets.slice(1);
  let keys = Object.keys(source);
  let keysLength = keys.length;
  let restLength = rest.length;
  let result = [];
  for (let keyIndex = 0; keyIndex < keysLength; keyIndex++) {
    let key = keys[keyIndex];
    let matched = true;
    for (let restIndex = 0; restIndex < restLength; restIndex++) {
      if (!rest[restIndex].hasOwnProperty(key)) {
        matched = false;
        break;
      }
    }
    if (matched) {
      result.push(source[key]);
    }
  }
  return result;
}
787917
def Intersect(self, other):
        
        if isinstance(other, Range):
            max_low = self.low if (self.low >= other.low) else other.low
            min_high = self.high if (self.high <= other.high) else other.high

            if max_low <= min_high:
                return True

        return False
671618
public static boolean isEqualOrNull( Object s1,
                                         Object s2 ) {
        if ( s1 == null
                && s2 == null ) {
            return true;
        } else if ( s1 != null
                && s2 != null
                && s1.equals( s2 ) ) {
            return true;
        }
        return false;
    }