Ejemplo n.º 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;
  }
Ejemplo n.º 2
0
  /**
   * IntHashSet specialised variant of {this#containsAll(Collection)}.
   *
   * @param other int hash set to compare against.
   * @return true if every element in other is in this.
   */
  public boolean containsAll(final IntHashSet other) {
    boolean containsAll = true;

    final int missingValue = this.missingValue;
    for (final int value : values) {
      if (value != missingValue && !other.contains(value)) {
        containsAll = false;
        break;
      }
    }

    return containsAll;
  }