/** * Constructs a new, empty metadata container which may pre-allocate * enough internal capacities to hold at least capacity entries. * * @param capacity The capacity to pre-allocate */ public MetadataContainer( int capacity ) { this.entries = new Byte2ObjectOpenHashMap<>( ( capacity > 32 ? 32 : capacity ) ); }
@Override public void clear() { Byte2ObjectOpenHashMap.this.clear(); } /** {@inheritDoc} */
@Override public boolean contains(Object v) { return containsValue(v); } @Override
@Override public void putAll(Map<? extends Byte, ? 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 byte 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 (((k) == ((byte) 0))) removeNullEntry(); else removeEntry(pos); return defRetValue; } return value[pos] = (newValue); } /*
/** {@inheritDoc} */ @Override public V computeIfPresent(final byte k, final java.util.function.BiFunction<? super Byte, ? 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(Byte.valueOf(k), (value[pos])); if (newValue == null) { if (((k) == ((byte) 0))) removeNullEntry(); else removeEntry(pos); return defRetValue; } return value[pos] = (newValue); } /** {@inheritDoc} */
/** * 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 Byte2ObjectOpenHashMap(final byte[] 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 replace(final byte 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 Byte2ObjectOpenHashMap(final Map<? extends Byte, ? extends V> m, final float f) { this(m.size(), f); putAll(m); } /**
public T get(byte[] key) { Node n = root; for (int i = 0; i < key.length; i++) { if ((n = n.map.get(key[i])) == null) { return null; } } return n.value; }
serialize(out, map.values().toArray()); } else if (oCls.equals(Byte2ObjectOpenHashMap.class)) { serialize(out, ((Byte2ObjectOpenHashMap) map).keySet().toByteArray()); serialize(out, map.values().toArray()); } else if (oCls.equals(Char2ObjectOpenHashMap.class)) {
/** {@inheritDoc} */ @Override public V compute(final byte k, final java.util.function.BiFunction<? super Byte, ? super V, ? extends V> remappingFunction) { java.util.Objects.requireNonNull(remappingFunction); final int pos = find(k); final V newValue = remappingFunction.apply(Byte.valueOf(k), pos >= 0 ? (value[pos]) : null); if (newValue == null) { if (pos >= 0) { if (((k) == ((byte) 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} */
/** {@inheritDoc} */ @Override public boolean replace(final byte 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 Byte2ObjectOpenHashMap(final Byte2ObjectMap<V> m, final float f) { this(m.size(), f); putAll(m); } /**
public T get(Buffer buffer, int count) { Node n = root; for (int i = 0; i < count; i++) { if ((n = n.map.get(buffer.readByte())) == null) { return null; } } return n.value; }
serialize(out, map.values().toArray()); } else if (oCls.equals(Byte2ObjectOpenHashMap.class)) { serialize(out, ((Byte2ObjectOpenHashMap) map).keySet().toByteArray()); serialize(out, map.values().toArray()); } else if (oCls.equals(Char2ObjectOpenHashMap.class)) {
return new Short2ObjectOpenHashMap(map); } else if (oCls.equals(Byte.class)) { return new Byte2ObjectOpenHashMap(map); } else if (oCls.equals(Long.class)) { return new Long2ObjectOpenHashMap(map);