/** * 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); } }
for (int i = 0; i < numValues; i++) { double value = sortedDoubles[i]; _doubleValueToIndexMap.put(value, i); writer.writeDouble(i, value);
/** * 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]); } /**
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()); }