Compute the set intersection size of two sets.

@param first First set
@param second Second set
@return size
511861
public static int intersectionSize(DBIDs first, DBIDs second) {
    // If exactly one is a Set, use it as second parameter.
    if(second instanceof SetDBIDs) {
      if(!(first instanceof SetDBIDs)) {
        return internalIntersectionSize(first, second);
      }
    }
    else if(first instanceof SetDBIDs) {
      return internalIntersectionSize(second, first);
    }
    // Both are the same type: both set or both non set.
    // Smaller goes first.
    return first.size() <= second.size() ? internalIntersectionSize(first, second) : internalIntersectionSize(second, first);
  }
29438
def intersection (set1, set2):
    
    assert is_iterable(set1)
    assert is_iterable(set2)
    result = []
    for v in set1:
        if v in set2:
            result.append (v)
    return result
1101456
public static <E> Set<E> difference(Set<E> first, Set<E> second) {
        if (first == null || first.size() == 0) {
            return new HashSet<>();
        }

        if (second == null || second.size() == 0) {
            return first;
        }

        Set<E> difference = new HashSet<>(first);
        difference.removeAll(second);
        return difference;
    }
711441
def intersection(self, other):
        
        if isinstance(other, self.__class__):
            return self.client.sinter([self.name, other.name])
        else:
            return self._as_set().intersection(other)
498284
public static long intersectionCount(OpenBitSet a, OpenBitSet b) {
        return BitUtil.pop_intersect( a.bits, b.bits, 0, Math.min( a.wlen, b.wlen ) );
    }
1175155
public static double[] intersection(double[] kb1, double[] kb2) {
    double[] interp = new double[2];
    if (kb1[0] == 1) {
      interp[0] = kb1[1];
      interp[1] = kb2[1] * interp[0] + kb2[2];
    } else if (kb2[0] == 1) {
      interp[0] = kb2[1];
      interp[1] = kb1[1] * interp[0] + kb1[2];
    } else {
      interp[0] = (kb2[2] - kb1[2]) / (kb1[1] - kb2[1]);
      interp[1] = kb1[1] * interp[0] + kb1[2];
    }
    return interp;

  }
144695
public int totalSize() {
        int size = 0;
        for (F first: keySet()) {
            size += getCounter(first).size();
        }

        return size;
    }
578716
public static <T> List<T> intersection(final List<? extends T> list1, final List<? extends T> list2) {
		List<? extends T> smaller = list1;
		List<? extends T> larger = list2;
		if (list1.size() > list2.size()) {
			smaller = list2;
			larger = list1;
		}

		// 克隆一个可修改的副本
		List<T> newSmaller = new ArrayList<T>(smaller);
		List<T> result = new ArrayList<T>(smaller.size());
		for (final T e : larger) {
			if (newSmaller.contains(e)) {
				result.add(e);
				newSmaller.remove(e);
			}
		}
		return result;
	}
1135948
function intersection( arr1, arr2 ){
	var rtn = [];

	if ( arr1.length > arr2.length ){
		let t = arr1;

		arr1 = arr2;
		arr2 = t;
	}

	for( let i = 0, c = arr1.length; i < c; i++ ){
		let d = arr1[i];

		if ( arr2.indexOf(d) !== -1 ){
			rtn.push( d );
		}
	}

	return rtn;
}
300127
public static final DimensionSpec mergeDimensions(int[] firstDimensionNums, int[] firstDimensionSizes,
      int[] secondDimensionNums, int[] secondDimensionSizes) {
    SortedSet<Integer> first = Sets.newTreeSet(Ints.asList(firstDimensionNums));
    SortedSet<Integer> second = Sets.newTreeSet(Ints.asList(secondDimensionNums));
    SortedSet<Integer> all = Sets.newTreeSet(first);
    all.addAll(second);
    
    int[] resultDims = Ints.toArray(all);
    int[] resultSizes = new int[resultDims.length];
    for (int i = 0; i < resultDims.length; i++) {
      int dim = resultDims[i];
      if (first.contains(dim) && second.contains(dim)) {
        int firstIndex = Ints.indexOf(firstDimensionNums, dim);
        int secondIndex = Ints.indexOf(secondDimensionNums, dim);
        int firstSize = firstDimensionSizes[firstIndex];
        int secondSize = secondDimensionSizes[secondIndex];
        Preconditions.checkArgument(firstSize == secondSize,
            "Dimension sizes do not match: dim %s, sizes %s and %s.", dim, firstSize, secondSize);
        resultSizes[i] = firstSize;
      } else if (first.contains(dim)) {
        int firstIndex = Ints.indexOf(firstDimensionNums, dim);
        int firstSize = firstDimensionSizes[firstIndex];
        resultSizes[i] = firstSize;
      } else {
        int secondIndex = Ints.indexOf(secondDimensionNums, dim);
        int secondSize = secondDimensionSizes[secondIndex];
        resultSizes[i] = secondSize;
      }
    }

    return new DimensionSpec(resultDims, resultSizes);
  }
920230
private static <T> List<T> intersect(T[] first, T[] second) {
    List<T> result = new ArrayList<>();
    for (T a : first) {
      for (T b : second) {
        if (a.equals(b)) {
          result.add(b);
          break;
        }
      }
    }
    return result;
  }
84759
public static double overlap(SpatialComparable box1, SpatialComparable box2) {
    final int dim = assertSameDimensionality(box1, box2);

    // the maximal and minimal value of the overlap box.
    double omax, omin;

    // the overlap volume
    double overlap = 1.;

    for(int i = 0; i < dim; i++) {
      // The maximal value of that overlap box in the current
      // dimension is the minimum of the max values.
      omax = Math.min(box1.getMax(i), box2.getMax(i));
      // The minimal value is the maximum of the min values.
      omin = Math.max(box1.getMin(i), box2.getMin(i));

      // if omax <= omin in any dimension, the overlap box has a volume of zero
      if(omax <= omin) {
        return 0.;
      }

      overlap *= omax - omin;
    }

    return overlap;
  }
799852
public int union(int first, int second) {
    int firstComponent = find(first), secondComponent = find(second);
    if(firstComponent == secondComponent) {
      return firstComponent;
    }
    final int w1 = weight[firstComponent], w2 = weight[secondComponent];
    if(w1 > w2) {
      parent[secondComponent] = firstComponent;
      weight[firstComponent] += w2;
      return firstComponent;
    }
    else {
      parent[firstComponent] = secondComponent;
      weight[secondComponent] += w1;
      return secondComponent;
    }
  }
150346
function(or1, or2) {
			var d1 = set.difference(or1, or2.values[0]);
			var d2 = set.difference(or1, or2.values[1]);
			return set.intersection(d1, d2);
		}
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
258385
public double evaluate(List<? extends Solution<?>> set1, List<? extends Solution<?>> set2) {
    double result ;
    int sum = 0 ;

    if (set2.size()==0) {
      if (set1.size()==0) {
        result = 0.0 ;
      } else {
        result = 1.0 ;
      }
    } else {
      for (Solution<?> solution : set2) {
        if (SolutionListUtils.isSolutionDominatedBySolutionList(solution, set1)) {
          sum++;
        }
      }
      result = (double)sum/set2.size() ;
    }
    return result ;
  }
455953
def intersection(a, b, scale=1):
    ''''''
    try:
        a1, a2 = a
    except TypeError:
        a1 = a.start
        a2 = a.stop

    try:
        b1, b2 = b
    except TypeError:
        b1 = b.start
        b2 = b.stop

    if a2 <= b1:
        return None
    if a1 >= b2:
        return None

    # a2 > b1 and a1 < b2

    if a2 <= b2:
        if a1 <= b1:
            return slice(b1 * scale, a2 * scale)
        else:
            return slice(a1 * scale, a2 * scale)
    else:
        if a1 <= b1:
            return slice(b1 * scale, b2 * scale)
        else:
            return slice(a1 * scale, b2 * scale)