/** * Gets the bin index for a value. The value is not added to the histogram. * * @param value the value * * @return the bin index or {@link #NO_BIN} */ public int getBinForValue(T value) { ensureBinsSorted(); return findBin(value); }
/** * Adds a value to the histogram. * * @param value the value * * @return the index of the bin that the value was allocated to or * {@link #NO_BIN} */ public int addValue(T value) { int index = getBinForValue(value); if (index != NO_BIN) { bins.get(index).count++; } return index; }
/** * Gets bin indices for a list of input values. The values are not added * to the histogram. * * @param values input values * * @return a new {@code List} of bin indices */ public List<Integer> getBinForValues(List<T> values) { List<Integer> indices = new ArrayList<Integer>(); for (T value : values) { indices.add(getBinForValue(value)); } return indices; }
/** * Adds a list of values to the histogram. This will be faster than * adding values one at a time if the list is at least partially * sorted. * * @param values input values */ public void addValues(List<T> values) { ensureBinsSorted(); int curIndex = NO_BIN; Bin bin = null; for (T value : values) { int index = findBin(value); if (index != NO_BIN) { if (index != curIndex) { bin = bins.get(index); curIndex = index; } bin.count++ ; } } }