/** * Reorders this K2V1 using {@code ordering}, which have the same length as this K2V1'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 K2V1<A, B, Q> reorder(int... ordering) { keys.reorder(ordering); ArrayTools.reorder(values, ordering); return this; }
/** * Generates a random ordering with rng and applies the same ordering to all keys and values this has; they will * maintain their current association to other keys and values but their ordering/indices will change. * @param rng an IRNG to produce the random ordering this will use * @return this for chaining */ public K2V1<A, B, Q> shuffle(IRNG rng) { int[] ordering = rng.randomOrdering(keys.keysA.size); keys.reorder(ordering); ArrayTools.reorder(values, ordering); return this; } /**
/** * Reorders this BundleBiMap using {@code ordering}, which has the same length as this object'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. The effects of this method, if called * with an ordering that has repeat occurrences of an int or contains ints that are larger than its size should * permit, are undefined other than the vague definition of "probably bad, unless you like crashes." * @param ordering an int array or vararg that must contain each int from 0 to {@link #size()} * @return this for chaining */ public BundleBundleBiMap<E1, E2> reorder(int... ordering) { if(ordering == null || ordering.length != bm.size()) return this; bm.reorder(ordering); int len = mm1.size(); for (int i = 0; i < len; i++) { IntVLA iv = mm1.get(i); for (int j = 0; j < iv.size; j++) { iv.set(i, ordering[iv.get(i)]); } } return this; }
/** * Reorders this BundleBiMap using {@code ordering}, which has the same length as this object'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. The effects of this method, if called * with an ordering that has repeat occurrences of an int or contains ints that are larger than its size should * permit, are undefined other than the vague definition of "probably bad, unless you like crashes." * @param ordering an int array or vararg that must contain each int from 0 to {@link #size()} * @return this for chaining */ public BundleBiMap<E, S> reorder(int... ordering) { if(ordering == null || ordering.length != bm.size()) return this; bm.reorder(ordering); int len = mm.size(); for (int i = 0; i < len; i++) { IntVLA iv = mm.get(i); for (int j = 0; j < iv.size; j++) { iv.set(i, ordering[iv.get(i)]); } } return this; }