/** * Reorders this K2 using {@code ordering}, which have the same length as this K2's {@link #size()} * and can be generated with {@link ArrayTools#range(int)} (which, if applied, would produce no * change to the current ordering), {@link IRNG#randomOrdering(int)} (which gives a random ordering, and if * applied immediately would be the same as calling {@link #shuffle(IRNG)}), or made in some other way. If you * already have an ordering and want to make a different ordering that can undo the change, you can use * {@link ArrayTools#invertOrdering(int[])} called on the original ordering. * @param ordering an int array or vararg that should contain each int from 0 to {@link #size()} (or less) * @return this for chaining */ public K2<A, B> reorder(int... ordering) { keysA.reorder(ordering); keysB.reorder(ordering); return this; }
/** * Reorders this MultiKey using {@code ordering}, which have the same length as this MultiKey's {@link #size()} * and can be generated with {@link ArrayTools#range(int)} (which, if applied, would produce no * change to the current ordering), {@link IRNG#randomOrdering(int)} (which gives a random ordering, and if * applied immediately would be the same as calling {@link #shuffle(IRNG)}), or made in some other way. If you * already have an ordering and want to make a different ordering that can undo the change, you can use * {@link ArrayTools#invertOrdering(int[])} called on the original ordering. * @param ordering an int array or vararg that should contain each int from 0 to {@link #size()} (or less) * @return this for chaining */ public MultiKey reorder(int... ordering) { if(ordering != null) { for (int i = 0; i < keyCount; i++) { keys[i].reorder(ordering); } } return this; }
/** * Generates a random ordering with rng and applies the same ordering to all kinds of keys this has; they will * maintain their current association to other keys but their ordering/indices will change. * @param rng an IRNG to produce the random ordering this will use * @return this for chaining */ public K2<A, B> shuffle(IRNG rng) { int[] ordering = rng.randomOrdering(keysA.size); keysA.reorder(ordering); keysB.reorder(ordering); return this; }
/** * Generates a random ordering with rng and applies the same ordering to all kinds of keys this has; they will * maintain their current association to other keys but their ordering/indices will change. * @param rng an IRNG to produce the random ordering this will use * @return this for chaining */ public MultiKey shuffle(IRNG rng) { if(keyCount > 0) { int[] ordering = rng.randomOrdering(keys[0].size); for (int i = 0; i < keyCount; i++) { keys[i].reorder(ordering); } } return this; }