Exemple #1
0
  /**
   * Fast Path set difference for comparison with another IntHashSet.
   *
   * <p>NB: garbage free in the identical case, allocates otherwise.
   *
   * @param other the other set to subtract
   * @return null if identical, otherwise the set of differences
   */
  public IntHashSet difference(final IntHashSet other) {
    Objects.requireNonNull(other);

    IntHashSet difference = null;

    final int missingValue = this.missingValue;
    for (final int value : values) {
      if (value != missingValue && !other.contains(value)) {
        if (difference == null) {
          difference = new IntHashSet(size, missingValue);
        }

        difference.add(value);
      }
    }

    return difference;
  }