@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; }
@Override public int put(double value) { int id = _valueToIdMap.get(value); if (id == INVALID_KEY) { id = _idToValueMap.size(); _valueToIdMap.put(value, id); _idToValueMap.add(value); } return id; }
/** * 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(); } /**
put(key, newVal); return newVal;
put(key, newVal); return newVal;
newValue = value; put(key, newValue); return newValue;
/** * 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; } /**
return drv; int newValue = (mappedValue).intValue(); put(key, newValue); return newValue;
/** * 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; } /**
return v; int newValue = mappingFunction.applyAsInt(key); put(key, newValue); return newValue;
return drv; int newValue = mappingFunction.get(key); put(key, newValue); return newValue;
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; }
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; }