/** * Gets the total number of bundle-to-single pairs in this BundleBiMap. * @return the total number of bundle keys (equivalently, the number of single keys) in this object */ public int size() { return bm.size(); }
/** * Gets the total number of bundle-to-single pairs in this BundleBiMap. * @return the total number of bundle keys (equivalently, the number of single keys) in this object */ public int size() { return bm.size(); }
/** * Returns true if index is between 0 (inclusive) and {@link #size()} (exclusive), or false otherwise. * @param index the index to check * @return true if index is a valid index in the ordering of this BundleBiMap */ public boolean containsIndex(int index) { return index >= 0 && index < bm.size(); }
/** * Returns true if index is between 0 (inclusive) and {@link #size()} (exclusive), or false otherwise. * @param index the index to check * @return true if index is a valid index in the ordering of this BundleBiMap */ public boolean containsIndex(int index) { return index >= 0 && index < bm.size(); }
/** * 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 BundleBiMap<E, S> shuffle(IRNG rng) { return reorder(rng.randomOrdering(bm.size())); }
/** * 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 BundleBundleBiMap<E1, E2> shuffle(IRNG rng) { return reorder(rng.randomOrdering(bm.size())); }
/** * 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; }
/** * 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; }
/** * Puts all unique A and B keys in {@code other} into this K2, respecting other's ordering. If an A or a B in other * is already present when this would add one, this will not put the A and B keys at that point in the iteration * order, and will place the next unique A and B it finds in the arguments at that position instead. * @param other another K2 collection with the same A and B types * @return true if this collection changed as a result of this call */ public boolean putAll(K2<? extends A, ? extends B> other) { if(other == null) return false; boolean changed = false; int sz = other.size(); for (int i = 0; i < sz; i++) { changed = put(other.getAAt(i), other.getBAt(i)) || changed; } return changed; }
/** * Adds a bundle of E keys and a S key at the same point in the ordering (the end) to this BundleBiMap. Neither * parameter can be present in this collection before this is called. * @param e an array of E keys to add; the array cannot already be present, nor can it be null * @param s e S key to add; cannot already be present * @return true if this collection changed as e result of this call */ public boolean put(Collection<? extends E> e, S s) { if(e == null) return false; int len = elements.size; elements.putAll(e); for (int i = len; i < elements.size; i++) { mm.add(new IntVLA(e.size())); } int[][] bundle = new int[][]{elements.getArray(e)}; if(!bm.put(bundle, s)) return false; len = bundle[0].length; for (int i = 0; i < len; i++) { mm.get(bundle[0][i]).add(bm.size()-1); } return true; } /**
/** * Adds a bundle of E keys, mixed with an int array of variations, and a S key at the same point in the ordering * (the end) to this BundleBiMap. Neither the S key nor the bundle (effectively, the pair of e and variation) can be * present in this collection before this is called. * @param e an array of E keys to add; the array cannot already have been inserted with an equivalent variation, nor can it be null * @param variation an int array that can be used to make a different version of e, i.e. the same things at different quantities; cannot be null * @param s e S key to add; cannot already be present * @return true if this collection changed as e result of this call */ public boolean put(Collection<? extends E> e, int[] variation, S s) { if(e == null || variation == null) return false; int len = elements.size; elements.putAll(e); for (int i = len; i < elements.size; i++) { mm.add(new IntVLA(e.size())); } int[][] bundle = new int[][]{elements.getArray(e), variation}; if(!bm.put(bundle, s)) return false; len = bundle[0].length; for (int i = 0; i < len; i++) { mm.get(bundle[0][i]).add(bm.size()-1); } return true; }
/** * Adds a bundle of E keys, mixed with an int array of variations, and a S key at the same point in the ordering * (the end) to this BundleBiMap. Neither the S key nor the bundle (effectively, the pair of e and variation) can be * present in this collection before this is called. * @param e an array of E keys to add; the array cannot already have been inserted with an equivalent variation, nor can it be null * @param variation an int array that can be used to make a different version of e, i.e. the same things at different quantities; cannot be null * @param s e S key to add; cannot already be present * @return true if this collection changed as e result of this call */ public boolean put(E[] e, int[] variation, S s) { if(e == null || variation == null) return false; int len = elements.size; elements.putAll(e); for (int i = len; i < elements.size; i++) { mm.add(new IntVLA(e.length)); } int[][] bundle = new int[][]{elements.getArray(e), variation}; if(!bm.put(bundle, s)) return false; for (int i = 0; i < e.length; i++) { mm.get(bundle[0][i]).add(bm.size()-1); } return true; } /**
/** * Adds a bundle of E keys and a S key at the same point in the ordering (the end) to this BundleBiMap. Neither * parameter can be present in this collection before this is called. * @param e an array of E keys to add; the array cannot already be present, nor can it be null * @param s e S key to add; cannot already be present * @return true if this collection changed as e result of this call */ public boolean put(E[] e, S s) { if(e == null) return false; int len = elements.size; elements.putAll(e); for (int i = len; i < elements.size; i++) { mm.add(new IntVLA(e.length)); } elements.putAll(e); int[][] bundle = new int[][]{elements.getArray(e)}; if(!bm.put(bundle, s)) return false; for (int i = 0; i < e.length; i++) { mm.get(bundle[0][i]).add(bm.size()-1); } return true; } /**