/** * Execute a function for each ID. * * @param action Action to execute */ default void forEachDouble(Consumer action) { for(DoubleDBIDListIter it = iter(); it.valid(); it.advance()) { action.accept(it, it.doubleValue()); } }
/** * Returns the difference of the two specified collection of IDs. * * @param ids1 the first collection * @param ids2 the second collection * @return the difference of ids1 minus ids2 */ public static ModifiableDBIDs difference(DBIDs ids1, DBIDs ids2) { ModifiableDBIDs result = DBIDUtil.newHashSet(ids1); result.removeDBIDs(ids2); return result; }
/** * Compute the median of an array efficiently using the QuickSelect method. * * Note: the array is <b>modified</b> by this. * * @param data Data to process * @param comparator Comparator to use * @return Median position */ public static int median(ArrayModifiableDBIDs data, Comparator<? super DBIDRef> comparator) { return median(data, comparator, 0, data.size()); }
/** * Produce a random shuffling of the given DBID array. * * @param ids Original DBIDs, no duplicates allowed * @param random Random generator */ public static void randomShuffle(ArrayModifiableDBIDs ids, Random random) { randomShuffle(ids, random, ids.size()); }
/** * Dereference a DBID reference. * * @param ref DBID reference * @return DBID */ public static DBID deref(DBIDRef ref) { return ref instanceof DBID ? (DBID) ref : importInteger(ref.internalGetIndex()); }
/** * QuickSelect is essentially quicksort, except that we only "sort" that half * of the array that we are interested in. * * Note: the array is <b>modified</b> by this. * * @param data Data to process * @param rank Rank position that we are interested in (integer!) */ public static void quickSelect(ModifiableDoubleDBIDList data, int rank) { quickSelect(data, 0, data.size(), rank); }
/** * Compute the median of an array efficiently using the QuickSelect method. * * Note: the array is <b>modified</b> by this. * * @param data Data to process * @param quant Quantile to compute * @return Quantile position */ public static int quantile(ModifiableDoubleDBIDList data, double quant) { return quantile(data, 0, data.size(), quant); }