/** * Constructor * @param initialSize the initial size for this index */ IndexOfDoubles(int initialSize) { super(Array.of(Double.class, initialSize)); this.indexMap = new TDoubleIntHashMap(initialSize, 0.75f, -1, -1); }
@Override public final Index<Double> copy() { try { final IndexOfDoubles clone = (IndexOfDoubles)super.copy(); clone.indexMap = new TDoubleIntHashMap(indexMap); return clone; } catch (Exception ex) { throw new IndexException("Failed to clone index", ex); } }
TDoubleIntHashMap map = counts.get(x[i]); if (map == null) counts.put(x[i], map = new TDoubleIntHashMap()); map.adjustOrPutValue(y[i], 1, 1);
/** * Returns an array containing the n greatest values. * @param array * @param n * @return */ public static int[] nGreatest(double[] array, int n) { TDoubleIntHashMap places = new TDoubleIntHashMap(); int i; double key; for (int j = 1; j < array.length; j++) { key = array[j]; for (i = j - 1; i >= 0 && array[i] < key; i--) { array[i + 1] = array[i]; } array[i + 1] = key; places.put(key, j); } int[] retVal = new int[n]; for (i = 0; i < n; i++) { retVal[i] = places.get(array[i]); } return retVal; }
double max = - Double.MAX_VALUE; TDoubleIntHashMap hist = new TDoubleIntHashMap(samples.length); for (int i = 0; i < samples.length; i++) { hist.adjustOrPutValue(samples[i], 1, 1);
/** * Constructor * @param iterable the keys for index */ IndexOfDoubles(Iterable<Double> iterable) { super(iterable); this.indexMap = new TDoubleIntHashMap(keyArray().length(), 0.75f, -1, -1); this.keyArray().sequential().forEachValue(v -> { final int index = v.index(); final double key = v.getDouble(); final int existing = indexMap.put(key, index); if (existing >= 0) { throw new IndexException("Cannot have duplicate keys in index: " + v.getValue()); } }); }
TDoubleIntHashMap counts = new TDoubleIntHashMap();
/** * Constructor * @param iterable the keys for index * @param parent the parent index to initialize from */ private IndexOfDoubles(Iterable<Double> iterable, IndexOfDoubles parent) { super(iterable, parent); this.indexMap = new TDoubleIntHashMap(keyArray().length(), 0.75f, -1, -1); this.keyArray().sequential().forEachValue(v -> { final double key = v.getDouble(); final int index = parent.indexMap.get(key); if (index < 0) throw new IndexException("No match for key: " + v.getValue()); final int existing = indexMap.put(key, index); if (existing >= 0) { throw new IndexException("Cannot have duplicate keys in index: " + v.getValue()); } }); }