/** * Constructor for the class. * Populates the value <-> mappings. * * @param dataBuffer Pinot data buffer * @param length Length of the dictionary */ public OnHeapFloatDictionary(PinotDataBuffer dataBuffer, int length) { super(dataBuffer, length, Float.BYTES, (byte) 0); _valToDictId = new Float2IntOpenHashMap(length); _valToDictId.defaultReturnValue(-1); _dictIdToVal = new float[length]; for (int dictId = 0; dictId < length; dictId++) { float value = getFloat(dictId); _dictIdToVal[dictId] = value; _valToDictId.put(value, dictId); } }
@Override public int indexOf(Object rawValue) { float value = getValue(rawValue); return _valToDictId.get(value); }
Float2IntOpenHashMap floatMap = new Float2IntOpenHashMap(); floatMap.defaultReturnValue(INVALID_ID); map = floatMap; break;
numValues = sortedFloats.length; Preconditions.checkState(numValues > 0); _floatValueToIndexMap = new Float2IntOpenHashMap(numValues); for (int i = 0; i < numValues; i++) { float value = sortedFloats[i]; _floatValueToIndexMap.put(value, i); writer.writeFloat(i, value);
/** {@inheritDoc} */ @Override public int merge(final float k, final int v, final java.util.function.BiFunction<? super Integer, ? super Integer, ? extends Integer> remappingFunction) { java.util.Objects.requireNonNull(remappingFunction); final int pos = find(k); if (pos < 0) { insert(-pos - 1, k, v); return v; } final Integer newValue = remappingFunction.apply(Integer.valueOf(value[pos]), Integer.valueOf(v)); if (newValue == null) { if ((Float.floatToIntBits(k) == 0)) removeNullEntry(); else removeEntry(pos); return defRetValue; } return value[pos] = (newValue).intValue(); } /*
@Override public void putAll(Map<? extends Float, ? extends Integer> 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 int computeIfPresent(final float k, final java.util.function.BiFunction<? super Float, ? super Integer, ? extends Integer> remappingFunction) { java.util.Objects.requireNonNull(remappingFunction); final int pos = find(k); if (pos < 0) return defRetValue; final Integer newValue = remappingFunction.apply(Float.valueOf(k), Integer.valueOf(value[pos])); if (newValue == null) { if ((Float.floatToIntBits(k) == 0)) removeNullEntry(); else removeEntry(pos); return defRetValue; } return value[pos] = (newValue).intValue(); } /** {@inheritDoc} */
public FloatToIdMap() { _valueToIdMap = new Float2IntOpenHashMap(); _valueToIdMap.defaultReturnValue(INVALID_KEY); _idToValueMap = new FloatArrayList(); }
/** * 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 Float2IntOpenHashMap(final float[] k, final int[] 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]); } /**
if ((Float.floatToIntBits(k) == 0)) { if (containsNullKey) return addToValue(n, incr); pos = n; containsNullKey = true; & mask]) == 0)) { if ((Float.floatToIntBits(curr) == Float.floatToIntBits(k))) return addToValue(pos, incr); while (!(Float.floatToIntBits(curr = key[pos = (pos + 1) & mask]) == 0)) if ((Float.floatToIntBits(curr) == Float.floatToIntBits(k))) return addToValue(pos, incr); value[pos] = defRetValue + incr; if (size++ >= maxFill) rehash(arraySize(size + 1, f)); if (ASSERTS) checkTable();
@Override public void clear() { Float2IntOpenHashMap.this.clear(); } }
/** {@inheritDoc} */ @Override public int replace(final float k, final int v) { final int pos = find(k); if (pos < 0) return defRetValue; final int oldValue = value[pos]; value[pos] = v; return oldValue; } /** {@inheritDoc} */
@Override public boolean contains(float k) { return containsKey(k); } @Override
@Override public boolean contains(int v) { return containsValue(v); } @Override
/** {@inheritDoc} */ @Override public int compute(final float k, final java.util.function.BiFunction<? super Float, ? super Integer, ? extends Integer> remappingFunction) { java.util.Objects.requireNonNull(remappingFunction); final int pos = find(k); final Integer newValue = remappingFunction.apply(Float.valueOf(k), pos >= 0 ? Integer.valueOf(value[pos]) : null); if (newValue == null) { if (pos >= 0) { if ((Float.floatToIntBits(k) == 0)) removeNullEntry(); else removeEntry(pos); } return defRetValue; } int newVal = (newValue).intValue(); if (pos < 0) { insert(-pos - 1, k, newVal); return newVal; } return value[pos] = newVal; } /** {@inheritDoc} */
@Override public void setData( int totalNumValues, float binSize, Float2IntMap... counts ) { totalHeights = new Float2IntOpenHashMap( ); totalHeights.defaultReturnValue( 0 ); for ( Float2IntMap countMap : counts ) { for ( Float2IntMap.Entry entry : countMap.float2IntEntrySet( ) ) { int sum = totalHeights.get( entry.getFloatKey( ) ); sum += entry.getIntValue( ); totalHeights.put( entry.getFloatKey( ), sum ); } } super.setData( totalNumValues, binSize, counts ); }
@Override public void clear() { Float2IntOpenHashMap.this.clear(); } /** {@inheritDoc} */
/** {@inheritDoc} */ @Override public boolean replace(final float k, final int oldValue, final int v) { final int pos = find(k); if (pos < 0 || !((oldValue) == (value[pos]))) return false; value[pos] = v; return true; } /** {@inheritDoc} */