public int addIfAbsent(final K k) { int kPos; if((kPos = getInt(k)) < 0) return add(k); return kPos; }
/** * Adds an A key and a B key at the same point in the ordering (the end) to this K2. Neither parameter can be * present in this collection before this is called. If you want to change or update an existing key, use * {@link #alterA(Object, Object)} or {@link #alterB(Object, Object)}. * @param a an A key to add; cannot already be present * @param b a B key to add; cannot already be present * @return true if this collection changed as a result of this call */ public boolean put(A a, B b) { if(!keysA.containsKey(a) && !keysB.containsKey(b)) { keysA.add(a); keysB.add(b); return true; } return false; }
body.add(null); raw = new ArrayList<>(corpus.length * 3 >> 2); raw.add(new IntVLA(128));
public void putAll(Collection<? extends K> keyColl) { if (f <= .5) ensureCapacity(keyColl.size()); // The resulting map will be sized for // keyColl.size() elements else tryCapacity(size() + keyColl.size()); // The resulting map will be // tentatively sized for size() + keyColl.size() elements Iterator<? extends K> it = keyColl.iterator(); while (it.hasNext()) add(it.next()); }
/** * Adds a key to each keyset at the same point in the ordering (the end) of this MultiKey. The length of k must * match the keyCount of this MultiKey, and the nth item in k will go into the nth keyset. No item in k can be * present in the matching keyset in this before this is called. If you want to change or update an existing key, * use {@link #alter(int, Object, Object)} or {@link #alterAt(int, int, Object)}. * @param k an array or varargs of keys to add after the last index of this MultiKey; length must equal keyCount * @return true if this collection changed as a result of this call */ public boolean put(Object... k) { if(k != null && keyCount > 0 && k.length == keyCount) { for (int i = 0; i < keyCount; i++) { if(keys[i].containsKey(k[i])) return false; } for (int i = 0; i < keyCount; i++) { keys[i].add(k[i]); } return true; } return false; }
@Override public void putAll(Map<? extends K, ? extends Integer> m) { if (f <= .5) ensureCapacity(m.size()); // The resulting map will be sized for // m.size() elements else tryCapacity(size() + m.size()); // The resulting map will be int n = m.size(); final Iterator<? extends K> i = m .keySet().iterator(); while (n-- != 0) { add(i.next()); } }
public int putInts(CharSequence name, int[][] item) { int i = names.getInt(name); if(i < 0) { i = names.size(); names.add(name); charMaps.add(null); intMaps.add(item); doubleMaps.add(null); floatMaps.add(null); } else { charMaps.set(i, null); intMaps.set(i, item); doubleMaps.set(i, null); floatMaps.set(i, null); } return i; } public int putDoubles(CharSequence name, double[][] item)
public int putChars(CharSequence name, char[][] item) { int i = names.getInt(name); if(i < 0) { i = names.size(); names.add(name); charMaps.add(item); intMaps.add(null); doubleMaps.add(null); floatMaps.add(null); } else { charMaps.set(i, item); intMaps.set(i, null); doubleMaps.set(i, null); floatMaps.set(i, null); } return i; } public int putInts(CharSequence name, int[][] item)
public int putDoubles(CharSequence name, double[][] item) { int i = names.getInt(name); if(i < 0) { i = names.size(); names.add(name); charMaps.add(null); intMaps.add(null); doubleMaps.add(item); floatMaps.add(null); } else { charMaps.set(i, null); intMaps.set(i, null); doubleMaps.set(i, item); floatMaps.set(i, null); } return i; } public int putFloats(CharSequence name, float[][] item)
public int putFloats(CharSequence name, float[][] item) { int i = names.getInt(name); if(i < 0) { i = names.size(); names.add(name); charMaps.add(null); intMaps.add(null); doubleMaps.add(null); floatMaps.add(item); } else { charMaps.set(i, null); intMaps.set(i, null); doubleMaps.set(i, null); floatMaps.set(i, item); } return i; } }
/** * 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) {
public void putAll(K[] keyArray) { int n = keyArray.length; if (f <= .5) ensureCapacity(n); // The resulting map will be sized for // m.size() elements else tryCapacity(size() + n); // The resulting map will be // tentatively sized for size() + keyArray.length elements for (int i = 0; i < n; i++) { add(keyArray[i]); } }
/** * Adds the given item to the table. * * Weight must be greater than 0. * * @param item the object to be added * @param weight the weight to be given to the added object * @return this for chaining */ public ProbabilityTable<T> add(T item, int weight) { if(weight <= 0) return this; int i = table.getInt(item); if (i < 0) { weights.insert(table.size, Math.max(0, weight)); table.add(item); int w = Math.max(0, weight); total += w; normalTotal += w; } else { int i2 = weights.get(i); int w = Math.max(0, i2 + weight); weights.set(i, w); total += w - i2; normalTotal += w - i2; } return this; }
GreasedRegion t, all = new GreasedRegion(map, 0); regions.add(all); names.add("unused0"); connections.add(new IntVLA(0)); for (int i = 0; i < rf.rooms.size(); i++) { all.andNot(t); t.writeIntsInto(map, names.size()); names.add("room"+names.size()); connections.add(new IntVLA(rf.rooms.getAt(i).size())); all.andNot(t); t.writeIntsInto(map, names.size()); names.add("corridor"+names.size()); connections.add(new IntVLA(rf.corridors.getAt(i).size())); all.andNot(t); t.writeIntsInto(map, names.size()); names.add("cave"+names.size()); connections.add(new IntVLA(rf.caves.getAt(i).size()));
@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; } };
/** * Constructor that allows you to specify the adjective and noun collections used by * {@link #toWordMnemonic(int, boolean)} as well as a seed. This should be useful when you want to enforce a stable * relationship between word mnemonics produced by {@link #toWordMnemonic(int, boolean)} and the int values they * decode to with {@link #fromWordMnemonic(String)}, because the default can change if the adjective and noun * collections in {@link Thesaurus} change. There should be a fairly large amount of unique adjectives and nouns; * {@code (long)adjectives.size() * nouns.size() * adjectives.size() * nouns.size()} should be at least 0x80000000L * (2147483648L), with case disregarded. If the total is less than that, not all possible ints can be encoded with * {@link #toWordMnemonic(int, boolean)}. Having 216 adjectives and 216 nouns is enough for a rough target. Each * word (adjectives and nouns alike) can have any characters in it except for space, since space is used during * decoding to separate words. * @param seed a long seed that will be used to randomize the syllables and words used. * @param adjectives a Collection of unique Strings (case-insensitive) that will be used as adjectives * @param nouns a Collection of unique Strings (case-insensitive) that will be used as nouns */ public Mnemonic(long seed, Collection<String> adjectives, Collection<String> nouns) { RNG rng = new RNG(new LightRNG(seed)); int[] order = rng.randomOrdering(431); int o; for (int i = 0; i < 256; i++) { o = order[i]; items.add(baseTriplets.substring(o * 3, o * 3 + 3)); } allAdjectives.putAll(adjectives); allAdjectives.shuffle(rng); allNouns.putAll(nouns); allNouns.shuffle(rng); } /**
for (int i = 0; i < 256; i++) { o = order[i]; items.add(baseTriplets.substring(o * 3, o * 3 + 3));
/** * Constructor for a Mnemonic generator that allows a different seed to be chosen, which will alter the syllables * produced by {@link #toMnemonic(long)} and the words produced by {@link #toWordMnemonic(int, boolean)} if you give * the same numeric argument to differently-seeded Mnemonic generators. Unless you know you need this, you should * probably use {@link #Mnemonic()} to ensure that your text can be decoded. * @param seed a long seed that will be used to randomize the syllables and words used. */ public Mnemonic(long seed) { RNG rng = new RNG(new LightRNG(seed)); int[] order = rng.randomOrdering(431); int o; for (int i = 0; i < 256; i++) { o = order[i]; items.add(baseTriplets.substring(o * 3, o * 3 + 3)); } for (int i = 0; i < adjective.size(); i++) { allAdjectives.putAll(adjective.getAt(i)); } allAdjectives.shuffle(rng); for (int i = 0; i < noun.size(); i++) { allNouns.putAll(noun.getAt(i)); } allNouns.shuffle(rng); }