@Override public void clear() { Float2ObjectOpenHashMap.this.clear(); } /** {@inheritDoc} */
@Override public boolean contains(Object v) { return containsValue(v); } @Override
@Override public void putAll(Map<? extends Float, ? extends V> m) { if (f <= .5) ensureCapacity(m.size()); // The resulting map will be sized for m.size() elements else tryCapacity(size() + m.size()); // The resulting map will be tentatively sized for size() + m.size() // elements super.putAll(m); }
/** {@inheritDoc} */ @Override public V merge(final float k, final V v, final java.util.function.BiFunction<? super V, ? super V, ? extends V> remappingFunction) { java.util.Objects.requireNonNull(remappingFunction); final int pos = find(k); if (pos < 0 || value[pos] == null) { if (v == null) return defRetValue; insert(-pos - 1, k, v); return v; } final V newValue = remappingFunction.apply((value[pos]), (v)); if (newValue == null) { if ((Float.floatToIntBits(k) == 0)) removeNullEntry(); else removeEntry(pos); return defRetValue; } return value[pos] = (newValue); } /*
/** {@inheritDoc} */ @Override public V computeIfPresent(final float k, final java.util.function.BiFunction<? super Float, ? super V, ? extends V> remappingFunction) { java.util.Objects.requireNonNull(remappingFunction); final int pos = find(k); if (pos < 0) return defRetValue; final V newValue = remappingFunction.apply(Float.valueOf(k), (value[pos])); if (newValue == null) { if ((Float.floatToIntBits(k) == 0)) removeNullEntry(); else removeEntry(pos); return defRetValue; } return value[pos] = (newValue); } /** {@inheritDoc} */
return new Int2ObjectOpenHashMap(map); } else if (oCls.equals(Float.class)) { return new Float2ObjectOpenHashMap(map); } else if (oCls.equals(Double.class)) { return new Double2ObjectOpenHashMap(map);
/** {@inheritDoc} */ @Override public V replace(final float k, final V v) { final int pos = find(k); if (pos < 0) return defRetValue; final V oldValue = value[pos]; value[pos] = v; return oldValue; } /** {@inheritDoc} */
/** * Creates a new hash map copying a given one. * * @param m * a {@link Map} to be copied into the new hash map. * @param f * the load factor. */ public Float2ObjectOpenHashMap(final Map<? extends Float, ? extends V> m, final float f) { this(m.size(), f); putAll(m); } /**
/** * Returns a hash code for this map. * * This method overrides the generic method provided by the superclass. Since * {@code equals()} is not overriden, it is important that the value returned by * this method is the same value as the one returned by the overriden method. * * @return a hash code for this map. */ @Override public int hashCode() { int h = 0; for (int j = realSize(), i = 0, t = 0; j-- != 0;) { while ((Float.floatToIntBits(key[i]) == 0)) i++; t = it.unimi.dsi.fastutil.HashCommon.float2int(key[i]); if (this != value[i]) t ^= ((value[i]) == null ? 0 : (value[i]).hashCode()); h += t; i++; } // Zero / null keys have hash zero. if (containsNullKey) h += ((value[n]) == null ? 0 : (value[n]).hashCode()); return h; } private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException {
serialize(out, map.values().toArray()); } else if (oCls.equals(Float2ObjectOpenHashMap.class)) { serialize(out, ((Float2ObjectOpenHashMap) map).keySet().toFloatArray()); serialize(out, map.values().toArray()); } else if (oCls.equals(Double2ObjectOpenHashMap.class)) {
/** * Creates a new hash map using the elements of two parallel arrays. * * @param k * the array of keys of the new hash map. * @param v * the array of corresponding values in the new hash map. * @param f * the load factor. * @throws IllegalArgumentException * if {@code k} and {@code v} have different lengths. */ public Float2ObjectOpenHashMap(final float[] k, final V[] v, final float f) { this(k.length, f); if (k.length != v.length) throw new IllegalArgumentException( "The key array and the value array have different lengths (" + k.length + " and " + v.length + ")"); for (int i = 0; i < k.length; i++) this.put(k[i], v[i]); } /**
/** {@inheritDoc} */ @Override public V compute(final float k, final java.util.function.BiFunction<? super Float, ? super V, ? extends V> remappingFunction) { java.util.Objects.requireNonNull(remappingFunction); final int pos = find(k); final V newValue = remappingFunction.apply(Float.valueOf(k), pos >= 0 ? (value[pos]) : null); if (newValue == null) { if (pos >= 0) { if ((Float.floatToIntBits(k) == 0)) removeNullEntry(); else removeEntry(pos); } return defRetValue; } V newVal = (newValue); if (pos < 0) { insert(-pos - 1, k, newVal); return newVal; } return value[pos] = newVal; } /** {@inheritDoc} */
return new Int2ObjectOpenHashMap(map); } else if (oCls.equals(Float.class)) { return new Float2ObjectOpenHashMap(map); } else if (oCls.equals(Double.class)) { return new Double2ObjectOpenHashMap(map);
/** {@inheritDoc} */ @Override public boolean replace(final float k, final V oldValue, final V v) { final int pos = find(k); if (pos < 0 || !java.util.Objects.equals(oldValue, value[pos])) return false; value[pos] = v; return true; } /** {@inheritDoc} */
/** * Creates a new hash map copying a given type-specific one. * * @param m * a type-specific map to be copied into the new hash map. * @param f * the load factor. */ public Float2ObjectOpenHashMap(final Float2ObjectMap<V> m, final float f) { this(m.size(), f); putAll(m); } /**
final V newValue[] = (V[]) new Object[newN + 1]; int i = n, pos; for (int j = realSize(); j-- != 0;) { while ((Float.floatToIntBits(key[--i]) == 0)); if (!(Float.floatToIntBits(newKey[pos = it.unimi.dsi.fastutil.HashCommon
serialize(out, map.values().toArray()); } else if (oCls.equals(Float2ObjectOpenHashMap.class)) { serialize(out, ((Float2ObjectOpenHashMap) map).keySet().toFloatArray()); serialize(out, map.values().toArray()); } else if (oCls.equals(Double2ObjectOpenHashMap.class)) {
/** {@inheritDoc} */ @Override public V computeIfAbsent(final float k, final java.util.function.DoubleFunction<? extends V> mappingFunction) { java.util.Objects.requireNonNull(mappingFunction); final int pos = find(k); if (pos >= 0) return value[pos]; final V newValue = mappingFunction.apply(k); insert(-pos - 1, k, newValue); return newValue; } /** {@inheritDoc} */