private void put(short key, String value) { keyToValue.put(key, value); valueToKey.put(value, key); }
private void put(short key, String value) { keyToValue.put(key, value); valueToKey.put(value, key); }
/** * 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 V replace(final short key, final V value) { return containsKey(key) ? put(key, value) : defaultReturnValue(); } /**
return v; V newValue = mappingFunction.apply(key); 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 short key, final V oldValue, final V newValue) { final V curValue = get(key); if (!java.util.Objects.equals(curValue, oldValue) || (curValue == defaultReturnValue() && !containsKey(key))) return false; put(key, newValue); return true; } /**
/** * If the value for the specified key is present, attempts to compute a new * mapping given the key and its current mapped value. * * @param key * key with which the specified value is to be associated. * @param remappingFunction * the function to compute a value. * * @return the new value associated with the specified key, or the * {@linkplain #defaultReturnValue() default return value} if none. * * @see java.util.Map#computeIfPresent(Object, java.util.function.BiFunction) * @since 8.0.0 */ default V computeIfPresent(final short key, final java.util.function.BiFunction<? super Short, ? super V, ? extends V> remappingFunction) { java.util.Objects.requireNonNull(remappingFunction); final V oldValue = get(key), drv = defaultReturnValue(); if (oldValue == drv && !containsKey(key)) return drv; final V newValue = remappingFunction.apply(Short.valueOf(key), (oldValue)); if (newValue == null) { remove(key); return drv; } put(key, newValue); return newValue; } /**
return drv; put(key, newValue); return newValue;
newValue = value; 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 V putIfAbsent(final short key, final V value) { final V v = get(key), drv = defaultReturnValue(); if (v != drv || containsKey(key)) return v; put(key, value); return drv; } /**
public void clear() { labelMap.clear(); idMap.clear(); garbageQueue.clear(); length = 0; // Add null type short id = intToShort(NULL_LABEL); length++; labelMap.put(null, id); idMap.put(id, null); }
public void clear() { labelMap.clear(); idMap.clear(); garbageQueue.clear(); length = 0; // Add null type short id = intToShort(NULL_LABEL); length++; labelMap.put(null, id); idMap.put(id, null); }
public boolean addType(final Object label, final int id) { short givenId = intToShort(id); short foundId = labelMap.getShort(label); if (foundId != NULL_SHORT && foundId != givenId) { throw new RuntimeException("This label '" + label + "' is already assigned to a different id"); } else if (idMap.containsKey(givenId)) { if ((label == null && idMap.get(givenId) == null) || idMap.get(givenId).equals(label)) { return false; } else { throw new RuntimeException("This id '" + id + "' is already assigned to a different label"); } } if (garbageQueue.contains(givenId)) { garbageQueue.remove(givenId); labelMap.put(label, givenId); idMap.put(givenId, label); } else { short insertId = intToShort(length++); while (insertId < givenId) { garbageQueue.add(insertId); insertId = intToShort(length++); if (length >= MAX_SIZE) { throw new RuntimeException("Maximum number of edge types reached at " + MAX_SIZE); } } labelMap.put(label, givenId); idMap.put(givenId, label); } return true; }
public boolean addType(final Object label, final int id) { short givenId = intToShort(id); short foundId = labelMap.getShort(label); if (foundId != NULL_SHORT && foundId != givenId) { throw new RuntimeException("This label '" + label + "' is already assigned to a different id"); } else if (idMap.containsKey(givenId)) { if ((label == null && idMap.get(givenId) == null) || idMap.get(givenId).equals(label)) { return false; } else { throw new RuntimeException("This id '" + id + "' is already assigned to a different label"); } } if (garbageQueue.contains(givenId)) { garbageQueue.remove(givenId); labelMap.put(label, givenId); idMap.put(givenId, label); } else { short insertId = intToShort(length++); while (insertId < givenId) { garbageQueue.add(insertId); insertId = intToShort(length++); if (length >= MAX_SIZE) { throw new RuntimeException("Maximum number of edge types reached at " + MAX_SIZE); } } labelMap.put(label, givenId); idMap.put(givenId, label); } return true; }
return drv; V newValue = mappingFunction.get(key); put(key, newValue); return newValue;
public EdgeTypeStore(Configuration config) { if (MAX_SIZE >= Short.MAX_VALUE - Short.MIN_VALUE + 1) { throw new RuntimeException("Edge Type Store size can't exceed 65534"); } this.configuration = config; this.garbageQueue = new ShortRBTreeSet(); this.labelMap = new Object2ShortOpenHashMap(MAX_SIZE); this.idMap = new Short2ObjectOpenHashMap(MAX_SIZE); labelMap.defaultReturnValue(NULL_SHORT); // Add null type short id = intToShort(NULL_LABEL); length++; labelMap.put(null, id); idMap.put(id, null); }
public EdgeTypeStore(Configuration config) { if (MAX_SIZE >= Short.MAX_VALUE - Short.MIN_VALUE + 1) { throw new RuntimeException("Edge Type Store size can't exceed 65534"); } this.configuration = config; this.garbageQueue = new ShortRBTreeSet(); this.labelMap = new Object2ShortOpenHashMap(MAX_SIZE); this.idMap = new Short2ObjectOpenHashMap(MAX_SIZE); labelMap.defaultReturnValue(NULL_SHORT); // Add null type short id = intToShort(NULL_LABEL); length++; labelMap.put(null, id); idMap.put(id, null); }
public int addType(final Object label) { checkType(label); short id = labelMap.getShort(label); if (id == NULL_SHORT) { if (!garbageQueue.isEmpty()) { id = garbageQueue.firstShort(); garbageQueue.remove(id); } else { id = intToShort(length); if (length >= MAX_SIZE) { throw new RuntimeException("Maximum number of edge types reached at " + MAX_SIZE); } length++; } labelMap.put(label, id); idMap.put(id, label); } return shortToInt(id); }
public int addType(final Object label) { checkType(label); short id = labelMap.getShort(label); if (id == NULL_SHORT) { if (!garbageQueue.isEmpty()) { id = garbageQueue.firstShort(); garbageQueue.remove(id); } else { id = intToShort(length); if (length >= MAX_SIZE) { throw new RuntimeException("Maximum number of edge types reached at " + MAX_SIZE); } length++; } labelMap.put(label, id); idMap.put(id, label); } return shortToInt(id); }
private EdgeTypeStore deserializeEdgeTypeStore(final DataInput is) throws IOException, ClassNotFoundException { int length = (Integer) deserialize(is); short[] ids = (short[]) deserialize(is); Object[] labels = (Object[]) deserialize(is); short[] garbage = (short[]) deserialize(is); EdgeTypeStore edgeTypeStore = model.store.edgeTypeStore; edgeTypeStore.length = length; for (int i = 0; i < ids.length; i++) { short id = ids[i]; Object label = labels[i]; edgeTypeStore.idMap.put(id, label); edgeTypeStore.labelMap.put(label, id); } for (int i = 0; i < garbage.length; i++) { edgeTypeStore.garbageQueue.add(garbage[i]); } return edgeTypeStore; }
private EdgeTypeStore deserializeEdgeTypeStore(final DataInput is) throws IOException, ClassNotFoundException { int length = (Integer) deserialize(is); short[] ids = (short[]) deserialize(is); Object[] labels = (Object[]) deserialize(is); short[] garbage = (short[]) deserialize(is); EdgeTypeStore edgeTypeStore = model.store.edgeTypeStore; edgeTypeStore.length = length; for (int i = 0; i < ids.length; i++) { short id = ids[i]; Object label = labels[i]; edgeTypeStore.idMap.put(id, label); edgeTypeStore.labelMap.put(label, id); } for (int i = 0; i < garbage.length; i++) { edgeTypeStore.garbageQueue.add(garbage[i]); } return edgeTypeStore; }