/** * {@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 boolean putIfAbsent(final byte key, final VType value) { if (!containsKey(key)) { put(key, value); return true; } return false; }
if (other.size() != this.size()) { return false; final EntryIterator it = this.iterator(); if (!other.containsKey(c.key)) { final VType otherValue = other.get(c.key);
@Override public int removeAll(final ByteContainer other) { final int before = this.size(); if (!((existing = keys[i]) == (byte)0) && other.contains(existing)) { shiftConflictingKeys(i); remove(((c.value))); return before - this.size();
/** * {@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(); }
/** * Creates a hash map from two index-aligned arrays of key-value pairs. Default load factor is used. */ public static <VType> ByteObjectHashMap<VType> from(final byte[] keys, final VType[] values) { if (keys.length != values.length) { throw new IllegalArgumentException("Arrays of keys and values must have an identical length."); } final ByteObjectHashMap<VType> map = new ByteObjectHashMap<VType>(keys.length); for (int i = 0; i < keys.length; i++) { map.put(keys[i], values[i]); } return map; }
/** * Create a new hash map with initial capacity and load factor control. * (constructor shortcut). */ public static <VType> ByteObjectHashMap<VType> newInstance(final int initialCapacity, final double loadFactor) { return new ByteObjectHashMap<VType>(initialCapacity, loadFactor); }
/** * {@inheritDoc} */ @Override public int putAll(final ByteObjectAssociativeContainer<? extends VType> container) { return putAll((Iterable<? extends ByteObjectCursor<? extends VType>>) 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 ByteObjectHashMap(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)); }
expandAndPut(key, value, slot); } else { this.assigned++;
/** * {@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(); }
/** * Create a hash map from another associative container. (constructor shortcut) Default load factor is used. */ public static <VType> ByteObjectHashMap<VType> from( final ByteObjectAssociativeContainer<VType> container) { return new ByteObjectHashMap<VType>(container); }
/** * Create a hash map from all key-value pairs of another container. */ public ByteObjectHashMap(final ByteObjectAssociativeContainer<VType> container) { this(container.size()); putAll(container); }
final VType[] oldValues = ((VType[])(this.values)); allocateBuffers(HashContainers.nextBufferSize(this.keys.length, this.assigned, this.loadFactor));
/** * Create a new hash map without providing the full generic signature * (constructor shortcut). */ public static <VType> ByteObjectHashMap<VType> newInstance() { return new ByteObjectHashMap<VType>(); }