/** * Constructs a K2 with the expected number of indices to hold (the number of A and number of B 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). * @param expected the amount of indices (the count of A items is the same as the count of B items) this should hold * @param f the load factor, probably between 0.1f and 0.8f */ public K2(int expected, float f) { keysA = new Arrangement<>(expected, f); keysB = new Arrangement<>(expected, f); }
public K2(K2<? extends A, ? extends B> other) { if(other == null) { keysA = new Arrangement<>(); keysB = new Arrangement<>(); } else { keysA = new Arrangement<>(other.keysA); keysB = new Arrangement<>(other.keysB); } }
/** * Constructs a MultiKey with the expected number of indices to hold (the number of items in each keyset 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). * @param expected the amount of indices (the number of items in each keyset is always the same) this should hold * @param f the load factor, probably between 0.1f and 0.8f */ public MultiKey(int keyCount, int expected, float f) { this.keyCount = keyCount; keys = new Arrangement[keyCount]; for (int i = 0; i < keyCount; i++) { keys[i] = new Arrangement(expected, f); } }
public MultiKey(MultiKey other) { if(other == null) { keyCount = 0; keys = new Arrangement[0]; } else { keyCount = other.keyCount; keys = new Arrangement[keyCount]; for (int i = 0; i < keyCount; i++) { keys[i] = new Arrangement(other.keys[i]); } } }
/** * Makes a Arrangement (Arrange) of T given an array or vararg of T elements. Duplicate items in elements will have * all but one item discarded, using the later item in elements. As is always the case with Arrangement, each item * will be mapped bi-directionally to its index in the iteration order, and an item can be retrieved with * {@link Arrangement#keyAt(int)} if you only know its index, or the int index for an item can be retrieved with * {@link Arrangement#getInt(Object)} if you only have an item. * @param elements an array or vararg of T * @param <T> just about any non-primitive type * @return a newly-allocated Arrangement containing all of the non-duplicate items in elements, in order */ @SuppressWarnings("unchecked") public static <T> Arrangement<T> makeArrange(T... elements) { if(elements == null) return null; return new Arrangement<>(elements); } /**
/** * Constructs a K2 with the expected number of indices to hold (the number of A and number of B items are always * equal, and this will be more efficient if expected is greater than that number), the load factor to use, * between 0.1f and 0.8f usually (using load factors higher than 0.8f can cause problems), and two IHasher * implementations, such as {@link CrossHash#generalHasher}, that will be used to hash and compare for equality with * A keys and B keys, respectively. Specifying an IHasher is usually needed if your keys are arrays (there are * existing implementations for 1D arrays of all primitive types, CharSequence, and Object in CrossHash), or if you * want hashing by identity and reference equality (which would use {@link CrossHash#identityHasher}, and might be * useful if keys are mutable). Other options are possible with custom IHashers, like hashing Strings but ignoring, * or only considering, a certain character for the hash and equality checks. * @param expected the amount of indices (the count of A items is the same as the count of B items) this should hold * @param f the load factor, probably between 0.1f and 0.8f * @param hasherA an implementation of CrossHash.IHasher meant for A keys * @param hasherB an implementation of CrossHash.IHasher meant for B keys */ public K2(int expected, float f, CrossHash.IHasher hasherA, CrossHash.IHasher hasherB) { keysA = new Arrangement<>(expected, f, hasherA); keysB = new Arrangement<>(expected, f, hasherB); }
/** * This shouldn't usually be used unless you for some reason need to construct a SectionMap before you have access * to a dungeon for it to map. If you do need this, then you must call {@link #reinitialize(RoomFinder)} to get any * use out of this object. * @see #SectionMap(RoomFinder) The preferred constructor, which takes a RoomFinder. */ public SectionMap() { map = new int[0][0]; names = new Arrangement<>(0); regions = new ArrayList<>(0); connections = new ArrayList<>(0); }
/** * Constructs a K2 from a pair of Iterables that will be processed in pairs, adding a unique A from aKeys if and * only if it can also add a unique B from bKeys, otherwise skipping that pair. * @param aKeys an Iterable of A that should all be unique * @param bKeys an Iterable of B that should all be unique */ public K2(Iterable<? extends A> aKeys, Iterable<? extends B> bKeys) { keysA = new Arrangement<>(); keysB = new Arrangement<>(); if(aKeys != null && bKeys != null) putAll(aKeys, bKeys); }
public GridData(int expectedSize) { names = new Arrangement<>(expectedSize, CrossHash.stringHasher); charMaps = new ArrayList<>(expectedSize); intMaps = new ArrayList<>(expectedSize); doubleMaps = new ArrayList<>(expectedSize); floatMaps = new ArrayList<>(expectedSize); } public boolean contains(CharSequence item)
/** * 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). * @param expected the amount of indices (the count of bundles is the same as the count of E2 items) this should hold * @param f the load factor, probably between 0.1f and 0.8f */ public BundleBundleBiMap(int expected, float f) { elements1 = new Arrangement<>(expected, f); elements2 = new Arrangement<>(expected, f); bm = new K2<>(expected, f, CrossHash.int2DHasher, CrossHash.int2DHasher); mm1 = new ArrayList<>(expected * 4); mm2 = new ArrayList<>(expected * 4); }
/** * Constructs a BundleBiMap with the expected number of indices to hold (the number of bundles and number of S 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). * @param expected the amount of indices (the count of bundles is the same as the count of S items) this should hold * @param f the load factor, probably between 0.1f and 0.8f */ public BundleBiMap(int expected, float f) { elements = new Arrangement<>(expected, f); bm = new K2<>(expected, f, CrossHash.int2DHasher, CrossHash.defaultHasher); mm = new ArrayList<>(expected * 4); }
public K2(Arrangement<A> aItems, Arrangement<B> bItems) { if(aItems == null || bItems == null) { keysA = new Arrangement<>(); keysB = new Arrangement<>(); } else { int amt = Math.min(aItems.size, bItems.size); keysA = aItems.take(amt); keysB = bItems.take(amt); } } /**
/** * Constructs a MultiKey from a Collection of Iterables that will be processed in tandem, adding a unique item from * each keyset in keysets if and only if it can also add a unique item from all other keysets, otherwise skipping * that iteration in each Iterable. * @param keysets a Collection of Iterable data structures, each containing items that should all be unique */ public MultiKey(Collection<Iterable> keysets) { if (keysets == null) { keyCount = 0; keys = new Arrangement[0]; } else { keyCount = keysets.size(); keys = new Arrangement[keyCount]; for (int i = 0; i < keyCount; i++) { keys[i] = new Arrangement(); } putAll(keysets); } }
/** * Constructs a BundleBiMap using another BundleBiMap to copy. * @param other the other BundleBiMap to copy */ public BundleBiMap(BundleBiMap<E, S> other) { if(other == null) { elements = new Arrangement<>(64, 0.75f); bm = new K2<>(16, 0.75f, CrossHash.int2DHasher, CrossHash.defaultHasher); mm = new ArrayList<>(64); } else { elements = new Arrangement<>(other.elements); bm = new K2<>(other.bm); mm = new ArrayList<>(other.mm); } }
/** * Copies the T items in {@link #body} and the int-based data structure {@link #processed} into a new MarkovObject. * None of the inner values, such as IntVLA values in processed, will be equivalent references, but the items in * body will be the same objects in both MarkovObject instances. * @return a copy of this MarkovObject */ public MarkovObject<T> copy() { MarkovObject<T> other = new MarkovObject<>(); other.body = new Arrangement<>(body); other.processed = new ArrayList<>(processed.size()); for (int i = 0; i < processed.size(); i++) { other.processed.add(new IntVLA(processed.get(i))); } return other; } }
/** * Creates a new probability table with the provided long seed used. * * @param seed the RNG seed as a long */ public ProbabilityTable(long seed) { this.rng = new GWTRNG(seed); table = new Arrangement<>(64, 0.75f); extraTable = new ArrayList<>(16); weights = new IntVLA(64); total = 0; normalTotal = 0; }
/** * Produces a copy of this Arrangement, but only using up to the given amount of items to take. Does a shallow copy * of individual keys, so the references will be shared. * @param amount the number of items to copy from this Arrangement; will copy all items if greater than size * @return a new Arrangement with up to amount items copied from this into it. */ public Arrangement<K> take(int amount) { amount = Math.min(size, Math.max(0, amount)); Arrangement<K> nx = new Arrangement<>(amount, f); for (int i = 0; i < amount; i++) { nx.add(keyAt(i)); } return nx; } protected int positionOf(final Object k) {
@Override public Arrangement<K> restore(String text) { ObText.ContentMatcher m = makeMatcher(text); Arrangement<K> d; if(convert.isArray) d = new Arrangement<>(CrossHash.generalHasher); else d = new Arrangement<>(); while (m.find()) { if (m.hasMatch()) { d.add(convert.restore(m.getMatch())); } } return d; } };
@Override @SuppressWarnings("unchecked") public Arrangement read(Json json, JsonValue jsonData, Class type) { if(jsonData == null || jsonData.isNull()) return null; return new Arrangement(json.readValue(OrderedSet.class, jsonData.get("k")), jsonData.getFloat("f")); } });
/** * Creates a new probability table with the provided source of randomness * used. * * @param rng the source of randomness */ public ProbabilityTable(RandomnessSource rng) { this.rng = rng == null ? new GWTRNG() : new GWTRNG(rng.next(32), rng.next(32)); table = new Arrangement<>(64, 0.75f); extraTable = new ArrayList<>(16); weights = new IntVLA(64); total = 0; normalTotal = 0; }