/** * @return Returns the current size (number of assigned keys) in the container. */ public int size() { return map.size(); }
/** * {@inheritDoc} */ public boolean isEmpty() { return size() == 0; }
@Override public int size() { return map.size(); }
/** * Return true if all keys of some other container exist in this container. * Values are compared using {@link Objects#equals(Object)} method. */ protected boolean equalElements(IntObjectHashMap<?> other) { if (other.size() != size()) { return false; } for (IntObjectCursor<?> c : other) { int key = c.key; if (!containsKey(key) || !java.util.Objects.equals(get(key), c.value)) { return false; } } return true; }
/** * {@inheritDoc} */ @Override public int removeAll(IntPredicate predicate) { final int before = size(); if (hasEmptyKey) { if (predicate.apply(0)) { hasEmptyKey = false; values[mask + 1] = null; } } final int[] keys = this.keys; for (int slot = 0, max = this.mask; slot <= max;) { int existing; if (!((existing = keys[slot]) == 0) && predicate.apply(existing)) { // Shift, do not increment slot. shiftConflictingKeys(slot); } else { slot++; } } return before - size(); }
/** * {@inheritDoc} */ @Override public int removeAll(IntObjectPredicate<? super VType> predicate) { final int before = size(); final int mask = this.mask; if (hasEmptyKey) { if (predicate.apply(0, (VType) values[mask + 1])) { hasEmptyKey = false; values[mask + 1] = null; } } final int[] keys = this.keys; final VType[] values = (VType[]) this.values; for (int slot = 0; slot <= mask;) { int existing; if (!((existing = keys[slot]) == 0) && predicate.apply(existing, values[slot])) { // Shift, do not increment slot. shiftConflictingKeys(slot); } else { slot++; } } return before - size(); }
/** * This method is invoked when there is a new key/ value pair to be inserted into * the buffers but there is not enough empty slots to do so. * * New buffers are allocated. If this succeeds, we know we can proceed * with rehashing so we assign the pending element to the previous buffer * (possibly violating the invariant of having at least one empty slot) * and rehash all keys, substituting new buffers at the end. */ protected void allocateThenInsertThenRehash(int slot, int pendingKey, VType pendingValue) { assert assigned == resizeAt && (( keys[slot]) == 0) && !((pendingKey) == 0); // Try to allocate new buffers first. If we OOM, we leave in a consistent state. final int[] prevKeys = this.keys; final VType[] prevValues = (VType[]) this.values; allocateBuffers(nextBufferSize(mask + 1, size(), loadFactor)); assert this.keys.length > prevKeys.length; // We have succeeded at allocating new data so insert the pending key/value at // the free slot in the old arrays before rehashing. prevKeys[slot] = pendingKey; prevValues[slot] = pendingValue; // Rehash old keys, including the pending key. rehash(prevKeys, prevValues); }
/** * @return Returns the current size (number of assigned keys) in the container. */ public int size() { return map.size(); }
/** * @return Returns the current size (number of assigned keys) in the container. */ public int size() { return map.size(); }
/** * @return Returns the current size (number of assigned keys) in the container. */ public int size() { return map.size(); }
/** * @return Returns the current size (number of assigned keys) in the container. */ public int size() { return map.size(); }
@Override public int size() { return map.size(); }
@Override public int size() { return map.size(); }
/** * @return Returns the current size (number of assigned keys) in the container. */ public int size() { return map.size(); }
/** * {@inheritDoc} */ public boolean isEmpty() { return size() == 0; }
@Override public int test() { final IntObjectHashMap<Integer> m_map = new IntObjectHashMap<>( m_keys.length, 0.5f ); for ( int i = 0; i < m_keys.length; ++i ) m_map.put( m_keys[ i ], null ); for ( int i = 0; i < m_keys.length; ++i ) m_map.put( m_keys[ i ], null ); return m_map.size(); } }