/** * {@inheritDoc} */ @Override public ByteByteHashMap clone() { //clone to size() to prevent some cases of exponential sizes, final ByteByteHashMap cloned = new ByteByteHashMap(this.size(), this.loadFactor); //We must NOT clone because of independent perturbations seeds cloned.putAll(this); return cloned; }
/** * {@inheritDoc} */ @Override public int capacity() { return this.owner.capacity(); }
/** * {@inheritDoc} * Alias for clear() the whole map. */ @Override public void clear() { this.owner.clear(); }
@Override public int removeAll(final byte e) { final boolean hasKey = this.owner.containsKey(e); int result = 0; if (hasKey) { this.owner.remove(e); result = 1; } return result; }
if (other.size() != this.size()) { return false; final EntryIterator it = this.iterator(); if (!other.containsKey(c.key)) { final byte otherValue = other.get(c.key);
/** * If <code>key</code> exists, <code>putValue</code> is inserted into the map, * otherwise any existing value is incremented by <code>additionValue</code>. * * @param key * The key of the value to adjust. * @param putValue * The value to put if <code>key</code> does not exist. * @param incrementValue * The value to add to the existing value if <code>key</code> exists. * @return Returns the current value associated with <code>key</code> (after * changes). */ @SuppressWarnings("cast") @Override public byte putOrAdd(final byte key, byte putValue, final byte incrementValue) { if (containsKey(key)) { putValue = get(key); putValue = (byte) (((putValue) + (incrementValue))); } put(key, putValue); return putValue; }
/** * {@inheritDoc} */ @Override public boolean putIfAbsent(final byte key, final byte value) { if (!containsKey(key)) { put(key, value); return true; } return false; }
/** * Creates a hash map from two index-aligned arrays of key-value pairs. Default load factor is used. */ public static ByteByteHashMap from(final byte[] keys, final byte[] values) { if (keys.length != values.length) { throw new IllegalArgumentException("Arrays of keys and values must have an identical length."); } final ByteByteHashMap map = new ByteByteHashMap(keys.length); for (int i = 0; i < keys.length; i++) { map.put(keys[i], values[i]); } return map; }
/** * Create a hash map from another associative container. (constructor shortcut) Default load factor is used. */ public static ByteByteHashMap from( final ByteByteAssociativeContainer container) { return new ByteByteHashMap(container); }
/** * {@inheritDoc} */ @Override public int putAll(final ByteByteAssociativeContainer container) { return putAll((Iterable<? extends ByteByteCursor>) container); }
/** * Creates a hash map with the given initial capacity, * load factor. * * @param loadFactor The load factor (greater than zero and smaller than 1). */ public ByteByteHashMap(final int initialCapacity, final double loadFactor) { this.loadFactor = loadFactor; //take into account of the load factor to guarantee no reallocations before reaching initialCapacity. allocateBuffers(HashContainers.minBufferSize(initialCapacity, loadFactor)); }
@Override public boolean contains(final byte e) { return containsKey(e); }
expandAndPut(key, value, slot); } else { this.assigned++;
/** * Create a new hash map without providing the full generic signature * (constructor shortcut). */ public static ByteByteHashMap newInstance() { return new ByteByteHashMap(); }
/** * Create a hash map from all key-value pairs of another container. */ public ByteByteHashMap(final ByteByteAssociativeContainer container) { this(container.size()); putAll(container); }
final byte[] oldValues = ((this.values)); allocateBuffers(HashContainers.nextBufferSize(this.keys.length, this.assigned, this.loadFactor));
/** * Create a new hash map with initial capacity and load factor control. * (constructor shortcut). */ public static ByteByteHashMap newInstance(final int initialCapacity, final double loadFactor) { return new ByteByteHashMap(initialCapacity, loadFactor); }
/** * {@inheritDoc} */ @Override public int capacity() { return this.owner.capacity(); }
@Override public void clear() { this.owner.clear(); }