/** * {@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 ByteObjectHashMap<VType> clone() { //clone to size() to prevent some cases of exponential sizes, final ByteObjectHashMap<VType> cloned = new ByteObjectHashMap<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 BytePredicate predicate) { final int before = this.size(); if (this.allocatedDefaultKey) { if (predicate.apply(((byte)0))) { this.allocatedDefaultKey = false; //help the GC this.allocatedDefaultKeyValue = (null); } } final byte[] keys = ((this.keys)); for (int i = 0; i < keys.length;) { byte existing; if (!((existing = keys[i]) == (byte)0) && predicate.apply(existing)) { shiftConflictingKeys(i); // Shift, do not increment slot. } else { i++; } } return before - this.size(); }
/** * {@inheritDoc} */ @Override public int removeAll(final ByteObjectPredicate<? super VType> predicate) { final int before = this.size(); if (this.allocatedDefaultKey) { if (predicate.apply(((byte)0), this.allocatedDefaultKeyValue)) { this.allocatedDefaultKey = false; //help the GC this.allocatedDefaultKeyValue = (null); } } final byte[] keys = ((this.keys)); final VType[] values = ((VType[])(this.values)); for (int i = 0; i < keys.length;) { byte existing; if (!((existing = keys[i]) == (byte)0) && predicate.apply(existing, values[i])) { shiftConflictingKeys(i); // Shift, do not increment slot. } else { i++; } } return before - this.size(); }