@SuppressWarnings("unchecked") private int getKeyForValue(double value) { Double2IntMap map = (Double2IntMap) _groupKeyMap; int groupId = map.get(value); if (groupId == INVALID_ID) { if (_numGroups < _globalGroupIdUpperBound) { groupId = _numGroups; map.put(value, _numGroups++); } } return groupId; }
public DoubleToIdMap() { _valueToIdMap = new Double2IntOpenHashMap(); _valueToIdMap.defaultReturnValue(INVALID_KEY); _idToValueMap = new DoubleArrayList(); }
/** * Removes the entry for the specified key only if it is currently mapped to the * specified value. * * @param key * key with which the specified value is associated. * @param value * value expected to be associated with the specified key. * * @return {@code true} if the value was removed. * * @see java.util.Map#remove(Object, Object) * @since 8.0.0 */ default boolean remove(final double key, final int value) { final int curValue = get(key); if (!((curValue) == (value)) || (curValue == defaultReturnValue() && !containsKey(key))) return false; remove(key); return true; } /**
/** * Replaces the entry for the specified key only if it is currently mapped to * some value. * * @param key * key with which the specified value is associated. * @param value * value to be associated with the specified key. * * @return the previous value associated with the specified key, or the * {@linkplain #defaultReturnValue() default return value} if there was * no mapping for the key. * * @see java.util.Map#replace(Object, Object) * @since 8.0.0 */ default int replace(final double key, final int value) { return containsKey(key) ? put(key, value) : defaultReturnValue(); } /**
/** * Returns the value to which the specified key is mapped, or the * {@code defaultValue} if this map contains no mapping for the key. * * @param key * the key. * @param defaultValue * the default mapping of the key. * * @return the value to which the specified key is mapped, or the * {@code defaultValue} if this map contains no mapping for the key. * * @see java.util.Map#getOrDefault(Object, Object) * @since 8.0.0 */ default int getOrDefault(final double key, final int defaultValue) { final int v; return ((v = get(key)) != defaultReturnValue() || containsKey(key)) ? v : defaultValue; } /**
private TimestampIndexStore deserializeTimestampIndexStore(final DataInput is) throws IOException, ClassNotFoundException { TimestampIndexStore timestampIndexStore; Class cls = (Class) deserialize(is); if (cls.equals(Node.class)) { timestampIndexStore = (TimestampIndexStore) model.store.timeStore.nodeIndexStore; } else { timestampIndexStore = (TimestampIndexStore) model.store.timeStore.edgeIndexStore; } int length = (Integer) deserialize(is); double[] doubles = (double[]) deserialize(is); int[] ints = (int[]) deserialize(is); int[] garbage = (int[]) deserialize(is); int[] counts = (int[]) deserialize(is); timestampIndexStore.length = length; for (int i : garbage) { timestampIndexStore.garbageQueue.add(i); } Double2IntMap m = timestampIndexStore.getMap(); for (int i = 0; i < ints.length; i++) { m.put(doubles[i], ints[i]); } timestampIndexStore.countMap = counts; return timestampIndexStore; }
@Override public boolean contains(final Object o) { if (!(o instanceof Map.Entry)) return false; if (o instanceof Double2IntMap.Entry) { final Double2IntMap.Entry e = (Double2IntMap.Entry) o; final double k = e.getDoubleKey(); return map.containsKey(k) && ((map.get(k)) == (e.getIntValue())); } final Map.Entry<?, ?> e = (Map.Entry<?, ?>) o; final Object key = e.getKey(); if (key == null || !(key instanceof Double)) return false; final double k = ((Double) (key)).doubleValue(); final Object value = e.getValue(); if (value == null || !(value instanceof Integer)) return false; return map.containsKey(k) && ((map.get(k)) == (((Integer) (value)).intValue())); }
@Override public int computeIfAbsent(final double key, final java.util.function.DoubleToIntFunction mappingFunction) { synchronized (sync) { return map.computeIfAbsent(key, mappingFunction); } } @Override
@Override public int computeIfPresent(final double key, final java.util.function.BiFunction<? super Double, ? super Integer, ? extends Integer> remappingFunction) { synchronized (sync) { return map.computeIfPresent(key, remappingFunction); } } @Override
@Override public int compute(final double key, final java.util.function.BiFunction<? super Double, ? super Integer, ? extends Integer> remappingFunction) { synchronized (sync) { return map.compute(key, remappingFunction); } } @Override
@Override public int computeIfAbsentNullable(final double key, final java.util.function.DoubleFunction<? extends Integer> mappingFunction) { synchronized (sync) { return map.computeIfAbsentNullable(key, mappingFunction); } } @Override
@Override public int computeIfAbsentPartial(final double key, final Double2IntFunction mappingFunction) { synchronized (sync) { return map.computeIfAbsentPartial(key, mappingFunction); } } @Override
/** * Replaces the entry for the specified key only if currently mapped to the * specified value. * * @param key * key with which the specified value is associated. * @param oldValue * value expected to be associated with the specified key. * @param newValue * value to be associated with the specified key. * * @return {@code true} if the value was replaced. * * @see java.util.Map#replace(Object, Object, Object) * @since 8.0.0 */ default boolean replace(final double key, final int oldValue, final int newValue) { final int curValue = get(key); if (!((curValue) == (oldValue)) || (curValue == defaultReturnValue() && !containsKey(key))) return false; put(key, newValue); return true; } /**
private TimestampIndexStore deserializeTimestampIndexStore(final DataInput is) throws IOException, ClassNotFoundException { TimestampIndexStore timestampIndexStore; Class cls = (Class) deserialize(is); if (cls.equals(Node.class)) { timestampIndexStore = (TimestampIndexStore) model.store.timeStore.nodeIndexStore; } else { timestampIndexStore = (TimestampIndexStore) model.store.timeStore.edgeIndexStore; } int length = (Integer) deserialize(is); double[] doubles = (double[]) deserialize(is); int[] ints = (int[]) deserialize(is); int[] garbage = (int[]) deserialize(is); int[] counts = (int[]) deserialize(is); timestampIndexStore.length = length; for (int i : garbage) { timestampIndexStore.garbageQueue.add(i); } Double2IntMap m = timestampIndexStore.getMap(); for (int i = 0; i < ints.length; i++) { m.put(doubles[i], ints[i]); } timestampIndexStore.countMap = counts; return timestampIndexStore; }
/** * {@inheritDoc} * * @deprecated Please use the corresponding type-specific method instead. */ @Deprecated @Override public Integer computeIfAbsent(final Double key, final java.util.function.Function<? super Double, ? extends Integer> mappingFunction) { synchronized (sync) { return map.computeIfAbsent(key, mappingFunction); } } /**
/** * {@inheritDoc} * * @deprecated Please use the corresponding type-specific method instead. */ @Deprecated @Override public Integer computeIfPresent(final Double key, final java.util.function.BiFunction<? super Double, ? super Integer, ? extends Integer> remappingFunction) { synchronized (sync) { return map.computeIfPresent(key, remappingFunction); } } /**
/** * {@inheritDoc} * * @deprecated Please use the corresponding type-specific method instead. */ @Deprecated @Override public Integer compute(final Double key, final java.util.function.BiFunction<? super Double, ? super Integer, ? extends Integer> remappingFunction) { synchronized (sync) { return map.compute(key, remappingFunction); } } /**
/** * If the specified key is not already associated with a value, associates it * with the given value and returns the {@linkplain #defaultReturnValue() * default return value}, else returns the current value. * * @param key * key with which the specified value is to be associated. * @param value * value to be associated with the specified key. * * @return the previous value associated with the specified key, or the * {@linkplain #defaultReturnValue() default return value} if there was * no mapping for the key. * * @see java.util.Map#putIfAbsent(Object, Object) * @since 8.0.0 */ default int putIfAbsent(final double key, final int value) { final int v = get(key), drv = defaultReturnValue(); if (v != drv || containsKey(key)) return v; put(key, value); return drv; } /**
final java.util.function.BiFunction<? super Double, ? super Integer, ? extends Integer> remappingFunction) { java.util.Objects.requireNonNull(remappingFunction); final int oldValue = get(key), drv = defaultReturnValue(); if (oldValue == drv && !containsKey(key)) return drv; final Integer newValue = remappingFunction.apply(Double.valueOf(key), Integer.valueOf(oldValue)); if (newValue == null) { remove(key); return drv; put(key, newVal); return newVal;