Here you can find the source of minMaxOverArraySubset(double[] array, Iterable
Parameter | Description |
---|---|
array | The array |
subset | The subset |
min | Min or max (true = min, false = max) |
public static double minMaxOverArraySubset(double[] array, Iterable<Integer> subset, boolean min)
//package com.java2s; // it under the terms of the GNU General Public License as published by public class Main { /**//w w w . j av a 2s . c o m * Compute the minimum or maximum value over a subset of an array of doubles. * @param array The array * @param subset The subset * @param min Min or max (true = min, false = max) */ public static double minMaxOverArraySubset(double[] array, Iterable<Integer> subset, boolean min) { if (min) return minOverArraySubset(array, subset); else return maxOverArraySubset(array, subset); } /** * Compute the minimum value over a subset of an array of doubles. * @param array The array * @param subset The subset */ public static double minOverArraySubset(double[] array, Iterable<Integer> subset) { double d; d = Double.POSITIVE_INFINITY; for (int j : subset) { if (array[j] < d) d = array[j]; } return d; } /** * Compute the maximum value over a subset of an array of doubles. * @param array The array * @param subset The subset */ public static double maxOverArraySubset(double[] array, Iterable<Integer> subset) { double d; d = Double.NEGATIVE_INFINITY; for (int j : subset) { if (array[j] > d) d = array[j]; } return d; } }