/** * Constructor for the class. * Populates the value <-> mappings. * * @param dataBuffer Pinot data buffer * @param length Length of the dictionary */ public OnHeapDoubleDictionary(PinotDataBuffer dataBuffer, int length) { super(dataBuffer, length, Double.BYTES, (byte) 0); _valToDictId = new Double2IntOpenHashMap(length); _valToDictId.defaultReturnValue(-1); _dictIdToVal = new double[length]; for (int dictId = 0; dictId < length; dictId++) { double value = getDouble(dictId); _dictIdToVal[dictId] = value; _valToDictId.put(value, dictId); } }
@Override public int indexOf(Object rawValue) { double value = getValue(rawValue); return _valToDictId.get(value); }
Double2IntOpenHashMap doubleMap = new Double2IntOpenHashMap(); doubleMap.defaultReturnValue(INVALID_ID); map = doubleMap; break;
private UniqueDouble(Var var, boolean sorted) { super(sorted); DoubleOpenHashSet keySet = new DoubleOpenHashSet(); for (int i = 0; i < var.rowCount(); i++) { keySet.add(var.getDouble(i)); } double[] elements = keySet.toDoubleArray(); if (sorted) { DoubleArrays.quickSort(elements, new UniqueDoubleComparator()); } Double2IntOpenHashMap uniqueKeys = new Double2IntOpenHashMap(); values = new DoubleArrayList(elements); for (int i = 0; i < elements.length; i++) { uniqueKeys.put(elements[i], i); } rowLists = new Int2ObjectOpenHashMap<>(); for (int i = 0; i < var.rowCount(); i++) { double key = var.getDouble(i); int id = uniqueKeys.get(key); if (!rowLists.containsKey(id)) { rowLists.put(id, new IntArrayList()); } rowLists.get(id).add(i); } updateIdsByRow(var.rowCount()); }
numValues = sortedDoubles.length; Preconditions.checkState(numValues > 0); _doubleValueToIndexMap = new Double2IntOpenHashMap(numValues); for (int i = 0; i < numValues; i++) { double value = sortedDoubles[i]; _doubleValueToIndexMap.put(value, i); writer.writeDouble(i, value);
@Override public void putAll(Map<? extends Double, ? 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); }
/** * 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 Double2IntOpenHashMap(final double[] 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]); } /**
public DoubleToIdMap() { _valueToIdMap = new Double2IntOpenHashMap(); _valueToIdMap.defaultReturnValue(INVALID_KEY); _idToValueMap = new DoubleArrayList(); }
if ((Double.doubleToLongBits(k) == 0)) { if (containsNullKey) return addToValue(n, incr); pos = n; containsNullKey = true; & mask]) == 0)) { if ((Double.doubleToLongBits(curr) == Double.doubleToLongBits(k))) return addToValue(pos, incr); while (!(Double.doubleToLongBits(curr = key[pos = (pos + 1) & mask]) == 0)) if ((Double.doubleToLongBits(curr) == Double.doubleToLongBits(k))) return addToValue(pos, incr); value[pos] = defRetValue + incr; if (size++ >= maxFill) rehash(arraySize(size + 1, f)); if (ASSERTS) checkTable();
@Override public void clear() { Double2IntOpenHashMap.this.clear(); } /** {@inheritDoc} */
@Override public boolean contains(double k) { return containsKey(k); } @Override
@Override public boolean contains(int v) { return containsValue(v); } @Override
@Override public void clear() { Double2IntOpenHashMap.this.clear(); } /** {@inheritDoc} */
case DOUBLE: for (int i = 0; i < multiValues.length; i++) { indexes[i] = _doubleValueToIndexMap.get((double) multiValues[i]);
@Override public void clear() { Double2IntOpenHashMap.this.clear(); } }
public int indexOfSV(Object value) { switch (_fieldSpec.getDataType()) { case INT: return _intValueToIndexMap.get((int) value); case LONG: return _longValueToIndexMap.get((long) value); case FLOAT: return _floatValueToIndexMap.get((float) value); case DOUBLE: return _doubleValueToIndexMap.get((double) value); case STRING: return _stringValueToIndexMap.getInt(value); case BYTES: return _bytesValueToIndexMap.get(new ByteArray((byte[]) value)); default: throw new UnsupportedOperationException("Unsupported data type : " + _fieldSpec.getDataType()); } }