public class BundleBundleBiMap<E1,E2>
extends java.lang.Object
Constructor and Description |
---|
BundleBundleBiMap()
Constructs an empty BundleBiMap.
|
BundleBundleBiMap(BundleBundleBiMap<E1,E2> other)
Constructs a BundleBiMap using another BundleBiMap to copy.
|
BundleBundleBiMap(int expected)
Constructs a BundleBiMap with the expected number of indices to hold (the number of bundles and number of E2 items
is always the same, and this will be more efficient if expected is greater than that number).
|
BundleBundleBiMap(int expected,
float f)
Constructs a BundleBiMap with the expected number of indices to hold (the number of bundles and number of E2 items
is always the same, and this will be more efficient if expected is greater than that number) and the load factor
to use, between 0.1f and 0.8f usually (using load factors higher than 0.8f can cause problems).
|
Modifier and Type | Method and Description |
---|---|
boolean |
containsElement1(E1 element)
Returns true if this contains the E1, element, in any of its bundles of E1 keys.
|
boolean |
containsElement2(E2 element)
Returns true if this contains the E2, element, in its collection of E2 items.
|
boolean |
containsIndex(int index)
Returns true if index is between 0 (inclusive) and
size() (exclusive), or false otherwise. |
squidpony.squidmath.OrderedSet<E1> |
elementsFromCode(int[][] bundle)
Given a coded bundle as produced by some methods in this class, decodes the elements1 part of the bundle and
returns it as a newly-allocated OrderedSet of E1 element keys.
|
int |
elementSize()
Gets the total number of unique E1 element keys across all bundles in this BundleBiMap.
|
squidpony.squidmath.OrderedSet<E1> |
getBundleElements(E2[] lookup)
Given an E2 key to look up, gets a (newly-allocated) OrderedSet of E1 element keys corresponding to that E2 key.
|
squidpony.squidmath.OrderedSet<E1> |
getBundleElementsAt(int index)
Given an index to look up, gets a (newly-allocated) OrderedSet of E1 element keys in the bundle at that index.
|
int[] |
getBundleVariationAt(int index)
Given an index to look up, gets a (newly-allocated) int array that is equivalent to the variation part of the
bundle present at that index.
|
int[][] |
getCodeAt(int index)
Given an index to look up, gets a 2D int array representing the bundle at that index.
|
int[] |
getElement1BundleVariation(E2[] lookup)
Given an E2 key to look up, gets a (newly-allocated) int array that is equivalent to the variation part of the
bundle corresponding to single.
|
squidpony.squidmath.OrderedSet<E1> |
getElement1OrderedSet()
To be called sparingly, since this allocates a new OrderedSet instead of reusing one.
|
java.util.SortedSet<E1> |
getElement1Set()
Gets and caches the individual E1 keys as a Collection that implements SortedSet (and so also implements Set).
|
squidpony.squidmath.OrderedSet<E2> |
getElement2(java.util.Collection<? extends E1> e1)
Given a bundle of E1 keys as a Collection with no variation, gets the matching E2 key for that bundle, or
null if there is none.
|
squidpony.squidmath.OrderedSet<E2> |
getElement2(java.util.Collection<? extends E1> e1,
int[] variations)
Given a bundle of E1 keys as a Collection with an int array variation, gets the matching E2 key for that bundle, or
null if there is none.
|
squidpony.squidmath.OrderedSet<E2> |
getElement2(E1[] e1)
Given a bundle of E1 keys as an array with no variation, gets the matching E2 key for that bundle, or null if there
is none.
|
squidpony.squidmath.OrderedSet<E2> |
getElement2(E1[] e1,
int[] variations)
Given a bundle of E1 keys as an array with an int array variation, gets the matching E2 key for that bundle, or
null if there is none.
|
squidpony.squidmath.OrderedSet<E2> |
getElement2At(int index)
Given an index to look up, gets the E2 key present at that position in the ordering.
|
int[][] |
getElement2Coded(int[][] code)
Given an E1 bundle as a coded 2D int array, gets the matching E2 bundle, also coded, or null if there is none.
|
squidpony.squidmath.OrderedSet<E2> |
getElement2OrderedSet()
To be called sparingly, since this allocates a new OrderedSet instead of reusing one.
|
java.util.SortedSet<E2> |
getElement2Set()
Gets and caches the E2 single keys as a Collection that implements SortedSet (and so also implements Set).
|
squidpony.squidmath.OrderedSet<int[][]> |
getManyCoded(E1 element)
Given an E1 element key that could be used in one or more bundles this uses, gets all bundles in this object that
contain the given element, as coded 2D int arrays.
|
squidpony.squidmath.OrderedSet<squidpony.squidmath.OrderedSet<? extends E2>> |
getManyElement2(E1 element)
Given an E1 element key that could be used in one or more bundles this uses, finds all E2 single keys corresponding
to bundles that contain the given element.
|
int[] |
getManyIndices(E1 element)
Given an E1 element key that could be used in one or more bundles this uses, gets all indices in the ordering
that contain a bundle with that element.
|
int |
indexOfElement2Coded(int[][] code)
Gets (in near-constant time) the index of the given E2 coded key in the ordering.
|
boolean |
isEmpty() |
java.util.Iterator<E1> |
iteratorElement1()
Creates a new iterator over the individual E1 element keys this holds, with a larger total count the iterator may
yield than
size() in most cases (it should be equal to elementSize() ), and in no particular
order (though the order should be stable across versions and platforms, no special means are provided to further
control the order). |
java.util.Iterator<E2> |
iteratorElement2()
Creates a new iterator over the E2 single keys this holds.
|
boolean |
put(java.util.Collection<? extends E1> e1,
java.util.Collection<? extends E2> e2)
Adds a bundle of E1 keys and a E2 key at the same point in the ordering (the end) to this BundleBiMap.
|
boolean |
put(java.util.Collection<? extends E1> e1,
int[] variation1,
java.util.Collection<? extends E2> e2,
int[] variation2)
Adds a bundle of E1 keys, mixed with an int array of variations, and a bundle of E2 keys at the same point in the
ordering (the end) to this BundleBiMap.
|
boolean |
put(E1[] e1,
E2[] e2)
Adds a bundle of E1 keys and a E2 key at the same point in the ordering (the end) to this BundleBiMap.
|
boolean |
put(E1[] e1,
int[] variation1,
E2[] e2,
int[] variation2)
Adds a bundle of E1 keys, mixed with an int array of variations, and a E2 key at the same point in the ordering
(the end) to this BundleBiMap.
|
boolean |
putAll(BundleBundleBiMap<? extends E1,? extends E2> other)
Puts all unique E1 and E2 keys in
other into this K2, respecting other's ordering. |
boolean |
putAll(java.lang.Iterable<? extends java.util.Collection<? extends E1>> aKeys,
java.lang.Iterable<? extends java.util.Collection<? extends E2>> bKeys)
Puts all unique E1 and E2 keys in
aKeys and bKeys into this K2 at the end. |
E1 |
randomElement1(squidpony.squidmath.IRNG random)
Gets a random E1 from this BundleBiMap's individual elements1 using the given IRNG.
|
E2 |
randomElement2(squidpony.squidmath.IRNG random)
Gets a random E2 from this BundleBiMap using the given IRNG.
|
BundleBundleBiMap<E1,E2> |
reorder(int... ordering)
Reorders this BundleBiMap using
ordering , which has the same length as this object's size()
and can be generated with ArrayTools.range(int) (which, if applied, would produce no
change to the current ordering), IRNG.randomOrdering(int) (which gives a random ordering, and if
applied immediately would be the same as calling shuffle(IRNG) ), or made in some other way. |
BundleBundleBiMap<E1,E2> |
shuffle(squidpony.squidmath.IRNG rng)
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.
|
int |
size()
Gets the total number of bundle-to-single pairs in this BundleBiMap.
|
int[] |
variationFromCode(int[][] bundle)
Given a coded bundle as produced by some methods in this class, decodes the variation part of the bundle, if
present, and returns it as a newly-allocated 1D int array.
|
public BundleBundleBiMap()
public BundleBundleBiMap(int expected)
expected
- how many bundle-to-single pairings this is expected to holdpublic BundleBundleBiMap(int expected, float f)
expected
- the amount of indices (the count of bundles is the same as the count of E2 items) this should holdf
- the load factor, probably between 0.1f and 0.8fpublic BundleBundleBiMap(BundleBundleBiMap<E1,E2> other)
other
- the other BundleBiMap to copypublic boolean containsElement1(E1 element)
element
- the E1 to check the presence of in all bundlespublic boolean containsElement2(E2 element)
element
- the E2 to check the presence ofpublic boolean containsIndex(int index)
size()
(exclusive), or false otherwise.index
- the index to checkpublic E1 randomElement1(squidpony.squidmath.IRNG random)
random
- generates a random index to get an E1 withpublic E2 randomElement2(squidpony.squidmath.IRNG random)
random
- generates a random index to get a E2 withpublic boolean put(E1[] e1, E2[] e2)
e1
- an array of E1 keys to add; the array cannot already be present, nor can it be nulle2
- an array of E2 keys to add; the array cannot already be present, nor can it be nullpublic boolean put(E1[] e1, int[] variation1, E2[] e2, int[] variation2)
e1
- an array of E1 keys to add; the array cannot already have been inserted with an equivalent variation, nor can it be nullvariation1
- an int array that can be used to make a different version of e1, i.e. the same things at different quantities; cannot be nulle2
- an array of E2 keys to add; the array cannot already have been inserted with an equivalent variation, nor can it be nullvariation2
- an int array that can be used to make a different version of e2, i.e. the same things at different quantities; cannot be nullpublic boolean put(java.util.Collection<? extends E1> e1, java.util.Collection<? extends E2> e2)
e1
- a Collection of E1 keys to add; the contents cannot already be present, nor can it be nulle2
- a Collection of E2 keys to add; the contents cannot already be present, nor can it be nullpublic boolean put(java.util.Collection<? extends E1> e1, int[] variation1, java.util.Collection<? extends E2> e2, int[] variation2)
e1
- a Collection of E1 keys to add; the Collection cannot already have been inserted with an equivalent variation, nor can it be nullvariation1
- an int array that can be used to make a different version of e1, i.e. the same things at different quantities; cannot be nulle2
- a Collection of E2 keys to add; the Collection cannot already have been inserted with an equivalent variation, nor can it be nullvariation2
- an int array that can be used to make a different version of e2, i.e. the same things at different quantities; cannot be nullpublic boolean putAll(java.lang.Iterable<? extends java.util.Collection<? extends E1>> aKeys, java.lang.Iterable<? extends java.util.Collection<? extends E2>> bKeys)
aKeys
and bKeys
into this K2 at the end. If an E1 in aKeys or a E2
in bKeys is already present when this would add one, this will not put the E1 and E2 keys at that point in the
iteration order, and will place the next unique E1 and E2 it finds in the arguments at that position instead.aKeys
- an Iterable or Collection of E1 keys to add; should all be unique (like a Set)bKeys
- an Iterable or Collection of E2 keys to add; should all be unique (like a Set)public boolean putAll(BundleBundleBiMap<? extends E1,? extends E2> other)
other
into this K2, respecting other's ordering. If an E1 or a E2 in other
is already present when this would add one, this will not put the E1 and E2 keys at that point in the iteration
order, and will place the next unique E1 and E2 it finds in the arguments at that position instead.other
- another K2 collection with the same E1 and E2 typespublic int[][] getCodeAt(int index)
put(Object[], int[], Object[], int[])
or put(Collection, int[], Collection, int[])
.
index
- an int index to look uppublic squidpony.squidmath.OrderedSet<E2> getElement2At(int index)
index
- an int index to look uppublic squidpony.squidmath.OrderedSet<E2> getElement2(E1[] e1)
e1
- an array of E1public squidpony.squidmath.OrderedSet<E2> getElement2(E1[] e1, int[] variations)
e1
- an array of E1 element keysvariations
- an int array that should match an int array used as a variation parameter to putpublic squidpony.squidmath.OrderedSet<E2> getElement2(java.util.Collection<? extends E1> e1)
e1
- a Collection of E1 element keys (each key can be an E1 or an instance of any subclass of E1)public squidpony.squidmath.OrderedSet<E2> getElement2(java.util.Collection<? extends E1> e1, int[] variations)
e1
- a Collection of E1 element keys (each key can be an E1 or an instance of any subclass of E1)variations
- an int array that should match an int array used as a variation parameter to putpublic int[][] getElement2Coded(int[][] code)
code
- a 2D int array representing a bundle that should have been obtained directly from this objectpublic int indexOfElement2Coded(int[][] code)
code
- a E2 coded key to look uppublic squidpony.squidmath.OrderedSet<E1> elementsFromCode(int[][] bundle)
bundle
- a coded bundle as a 2D int arraypublic int[] variationFromCode(int[][] bundle)
bundle
- a coded bundle as a 2D int arraypublic squidpony.squidmath.OrderedSet<E1> getBundleElements(E2[] lookup)
getElement1BundleVariation(Object[])
.lookup
- a E2 key to look uppublic int[] getElement1BundleVariation(E2[] lookup)
getBundleElements(Object[])
.lookup
- a bundle of E2 keys to look uppublic squidpony.squidmath.OrderedSet<E1> getBundleElementsAt(int index)
getBundleVariationAt(int)
.index
- an int position in the ordering to look uppublic int[] getBundleVariationAt(int index)
getBundleElementsAt(int)
.index
- an int position in the ordering to look uppublic squidpony.squidmath.OrderedSet<squidpony.squidmath.OrderedSet<? extends E2>> getManyElement2(E1 element)
element
- an E1 element key to look up (probably a component of one or more bundles)public squidpony.squidmath.OrderedSet<int[][]> getManyCoded(E1 element)
elementsFromCode(int[][])
and variationFromCode(int[][])
to get usable information from them.element
- an E1 element key to look up (probably a component of one or more bundles)public int[] getManyIndices(E1 element)
getElement2At(int)
(int)} to get the
E2 key at that position, getBundleElementsAt(int)
to get the E1 element keys at that position,
getBundleVariationAt(int)
to get the possible variation at that position, or getCodeAt(int)
to
get the coded bundle at that position.public BundleBundleBiMap<E1,E2> reorder(int... ordering)
ordering
, which has the same length as this object's size()
and can be generated with ArrayTools.range(int)
(which, if applied, would produce no
change to the current ordering), IRNG.randomOrdering(int)
(which gives a random ordering, and if
applied immediately would be the same as calling 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
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."ordering
- an int array or vararg that must contain each int from 0 to size()
public BundleBundleBiMap<E1,E2> shuffle(squidpony.squidmath.IRNG rng)
rng
- an IRNG to produce the random ordering this will usepublic java.util.Iterator<E1> iteratorElement1()
size()
in most cases (it should be equal to elementSize()
), and in no particular
order (though the order should be stable across versions and platforms, no special means are provided to further
control the order). The E1 keys are individual, not bundled, and duplicate keys should never be encountered even
if an E1 key appears in many bundles.public java.util.Iterator<E2> iteratorElement2()
size()
. This method can be problematic for garbage collection if called very frequently; it may be
better to access items by index (which also lets you access other keys associated with that index) using
getElement2At(int)
in a for(int i=0...) loop.public java.util.SortedSet<E1> getElement1Set()
public java.util.SortedSet<E2> getElement2Set()
public squidpony.squidmath.OrderedSet<E1> getElement1OrderedSet()
public squidpony.squidmath.OrderedSet<E2> getElement2OrderedSet()
public int size()
public int elementSize()
size()
, and ordinarily a fair amount larger, though this can also be smaller.public boolean isEmpty()
Copyright © Eben Howard 2012–2022. All rights reserved.