/** * Gets the key at the given index in the iteration order in constant time (random-access). * @param idx the index in the iteration order of the key to fetch * @return the key at the index, if the index is valid, otherwise null */ public K keyAt(final int idx) { if (idx < 0 || idx >= order.size) return null; // The starting point. return key[order.get(idx)]; }
/** * Gets the item at the given index in the iteration order in constant time (random-access). * * @param idx the index in the iteration order of the key to fetch * @return the key at the index, if the index is valid, otherwise null */ public K getAt(final int idx) { if (idx < 0 || idx >= order.size) return null; final K[] key = this.key; // The starting point. return key[order.get(idx)]; }
/** * Gets the key at the given index in the iteration order in constant time (random-access). * @param idx the index in the iteration order of the key to fetch * @return the key at the index, if the index is valid, otherwise null */ public K keyAt(final int idx) { if (idx < 0 || idx >= order.size) return null; // The starting point. return key[order.get(idx)]; }
/** * Gets the key at the given index in the iteration order in constant time (random-access). * @param idx the index in the iteration order of the key to fetch * @return the key at the index, if the index is valid, otherwise 0 */ public int keyAt(final int idx) { if (idx < 0 || idx >= order.size) return 0; // The starting point. return key[order.get(idx)]; }
/** * Gets the key at the given index in the iteration order in constant time (random-access). * @param idx the index in the iteration order of the key to fetch * @return the key at the index, if the index is valid, otherwise null */ public K keyAt(final int idx) { if (idx < 0 || idx >= order.size) return null; // The starting point. return key[order.get(idx)]; }
/** * Gets the value at the given index in the iteration order in constant time (random-access). * @param idx the index in the iteration order of the value to fetch * @return the value at the index, if the index is valid, otherwise the default return value */ public int getAt(final int idx) { int pos; if (idx < 0 || idx >= order.size) return defRetValue; // The starting point. if (key[pos = order.get(idx)] == 0) return containsNullKey ? value[n] : defRetValue; return value[pos]; } /**
/** * Gets the value at the given index in the iteration order in constant time (random-access). * @param idx the index in the iteration order of the value to fetch * @return the value at the index, if the index is valid, otherwise the default return value */ public V getAt(final int idx) { int pos; if (idx < 0 || idx >= order.size) return defRetValue; // The starting point. if (key[pos = order.get(idx)] == null) return containsNullKey ? value[n] : defRetValue; return value[pos]; } /**
/** * Gets the value at the given index in the iteration order in constant time (random-access). * @param idx the index in the iteration order of the value to fetch * @return the value at the index, if the index is valid, otherwise the default return value */ public int getAt(final int idx) { int pos; if (idx < 0 || idx >= order.size) return defRetValue; // The starting point. if (key[pos = order.get(idx)] == null) return containsNullKey ? value[n] : defRetValue; return value[pos]; } /**
/** * Returns the weight of the extra table if present. Returns zero * if the extra table is not present. * * @param item the extra ProbabilityTable to search for * @return the weight of the ProbabilityTable, or zero */ public int weight(ProbabilityTable<T> item) { int i = extraTable.indexOf(item); return i < 0 ? 0 : weights.get(i + table.size()); }
/** * Gets the key-value Map.Entry at the given index in the iteration order in constant time (random-access). * @param idx the index in the iteration order of the entry to fetch * @return the key-value entry at the index, if the index is valid, otherwise null */ public Entry<K, Integer> entryAt(final int idx) { if (idx < 0 || idx >= order.size) return null; return new MapEntry(order.get(idx)); }
/** * Gets the key-value Map.Entry at the given index in the iteration order in constant time (random-access). * @param idx the index in the iteration order of the entry to fetch * @return the key-value entry at the index, if the index is valid, otherwise null */ public Entry<K, V> entryAt(final int idx) { if (idx < 0 || idx >= order.size) return null; return new MapEntry(order.get(idx)); }
public int nextEntry() { if (!hasNext()) throw new NoSuchElementException(); curr = next; if(++index >= order.size) next = -1; else next = order.get(index);//(int) link[curr]; prev = curr; return curr; } public int previousEntry() {
/** * Gets the key-value Map.Entry at the given index in the iteration order in constant time (random-access). * @param idx the index in the iteration order of the entry to fetch * @return the key-value entry at the index, if the index is valid, otherwise null */ public MapEntry entryAt(final int idx) { if (idx < 0 || idx >= order.size) return null; return new MapEntry(order.get(idx)); }
/** * Returns the weight of the item if the item is in the table. Returns zero * if the item is not in the table. * * @param item the item searched for * @return the weight of the item, or zero */ public int weight(T item) { int i = table.getInt(item); return i < 0 ? 0 : weights.get(i); }
public int previousEntry() { if (!hasPrevious()) throw new NoSuchElementException(); curr = prev; if(--index < 1) prev = -1; else prev = order.get(index - 1); //prev = (int) (link[curr] >>> 32); next = curr; return curr; } public void remove() {
/** * Totals the lowest n numbers in the pool. * * @param n the number of dice to be totaled * @param pool the dice to pick from * @return the sum */ private int worstOf(int n, IntVLA pool) { int rolls = Math.min(n, pool.size); pool.sort(); int ret = 0; for (int r = 0; r < rolls; r++) { ret += pool.get(r); } return ret; }
/** * Removes the key and value at the given index in the iteration order in not-exactly constant time (though it still * should be efficient). * @param idx the index in the iteration order of the key and value to remove * @return the value removed, if there was anything removed, or the default return value otherwise (often null) */ public V removeAt(final int idx) { if (idx < 0 || idx >= order.size) return defRetValue; int pos = order.get(idx); if (key[pos] == null) { if (containsNullKey) return removeNullEntry(); return defRetValue; } return removeEntry(pos); } /**
/** * Randomly alters the iteration order for this MultiArrangement using the given IRNG to shuffle. * @param rng used to generate a random ordering * @return this for chaining */ public MultiArrangement<K> shuffle(IRNG rng) { if(order.size < 2) return this; order.shuffle(rng); first = order.get(0); last = order.peek(); fixValues(); return this; }
public OrderedSet<K> keysAt(IntVLA positions) { if(keys == null || positions == null || positions.size <= 0) return new OrderedSet<K>(); OrderedSet<K> ks = new OrderedSet<>(positions.size); for(int i = 0; i < positions.size; i++) { ks.add(keyAt(positions.get(i))); } return ks; }
public OrderedSet<K> keysAt(IntVLA positions) { if(keys == null || positions == null || positions.size <= 0) return new OrderedSet<K>(); OrderedSet<K> ks = new OrderedSet<>(positions.size); for(int i = 0; i < positions.size; i++) { ks.add(keyAt(positions.get(i))); } return ks; }