Esempio n. 1
0
  /** {@inheritDoc} */
  @Override
  public int removeAll(final KTypePredicate<? super KType> predicate) {
    final int before = this.size();

    if (this.allocatedDefaultKey) {

      if (predicate.apply(Intrinsics.<KType>empty())) {
        this.allocatedDefaultKey = false;
      }
    }

    final KType[] keys = Intrinsics.<KType[]>cast(this.keys);

    for (int i = 0; i < keys.length; ) {
      KType existing;
      if (!Intrinsics.<KType>isEmpty(existing = keys[i]) && predicate.apply(existing)) {

        shiftConflictingKeys(i);
        // Shift, do not increment slot.
      } else {
        i++;
      }
    }

    return before - this.size();
  }
Esempio n. 2
0
  /** {@inheritDoc} */
  @Override
  public boolean remove(final KType key) {

    if (Intrinsics.<KType>isEmpty(key)) {

      if (this.allocatedDefaultKey) {

        this.allocatedDefaultKey = false;
        return true;
      }

      return false;
    }

    final int mask = this.keys.length - 1;

    final KType[] keys = Intrinsics.<KType[]>cast(this.keys);

    int slot = REHASH(key) & mask;
    KType existing;

    /*! #if ($RH) !*/
    int dist = 0;
    final int[] cached = this.hash_cache;
    /*! #end !*/

    while (!Intrinsics.<KType>isEmpty(existing = keys[slot])
        /*! #if ($RH) !*/ && dist <= probe_distance(slot, cached) /*! #end !*/) {
      if (KEYEQUALS(key, existing)) {

        shiftConflictingKeys(slot);
        return true;
      }
      slot = (slot + 1) & mask;

      /*! #if ($RH) !*/
      dist++;
      /*! #end !*/
    } // end while true

    return false;
  }