/** * {@inheritDoc} * * <p>Note that an empty container may still contain many deleted keys (that occupy buffer * space). Adding even a single element to such a container may cause rehashing.</p> */ @Override public boolean isEmpty() { return size() == 0; }
/** * {@inheritDoc} */ @Override public int putAll(final Iterable<? extends ObjectObjectCursor<? extends KType, ? extends VType>> iterable) { final int count = this.size(); for (final ObjectObjectCursor<? extends KType, ? extends VType> c : iterable) { put(c.key, c.value); } return this.size() - count; }
/** * {@inheritDoc} */ @Override public ObjectObjectHashMap<KType, VType> clone() { //clone to size() to prevent some cases of exponential sizes, final ObjectObjectHashMap<KType, VType> cloned = new ObjectObjectHashMap<KType, VType>(this.size(), this.loadFactor); //We must NOT clone because of independent perturbations seeds cloned.putAll(this); return cloned; }
/** * {@inheritDoc} */ @Override public int removeAll(final ObjectObjectPredicate<? super KType, ? super VType> predicate) { final int before = this.size(); if (this.allocatedDefaultKey) { if (predicate.apply((null), this.allocatedDefaultKeyValue)) { this.allocatedDefaultKey = false; //help the GC this.allocatedDefaultKeyValue = (null); } } final KType[] keys = ((KType[])(this.keys)); final VType[] values = ((VType[])(this.values)); for (int i = 0; i < keys.length;) { KType existing; if (!((existing = keys[i]) == null) && predicate.apply(existing, values[i])) { shiftConflictingKeys(i); // Shift, do not increment slot. } else { i++; } } return before - this.size(); }
/** * {@inheritDoc} */ @Override public int removeAll(final ObjectPredicate<? super KType> predicate) { final int before = this.size(); if (this.allocatedDefaultKey) { if (predicate.apply((null))) { this.allocatedDefaultKey = false; //help the GC this.allocatedDefaultKeyValue = (null); } } final KType[] keys = ((KType[])(this.keys)); for (int i = 0; i < keys.length;) { KType existing; if (!((existing = keys[i]) == null) && predicate.apply(existing)) { shiftConflictingKeys(i); // Shift, do not increment slot. } else { i++; } } return before - this.size(); }