public SortedDimensionDictionary(List<String> idToValue, int length) { Object2IntSortedMap<String> sortedMap = new Object2IntRBTreeMap<>(Comparators.naturalNullsFirst()); for (int id = 0; id < length; id++) { String value = idToValue.get(id); sortedMap.put(value, id); } this.sortedVals = Lists.newArrayList(sortedMap.keySet()); this.idToIndex = new int[length]; this.indexToId = new int[length]; int index = 0; for (IntIterator iterator = sortedMap.values().iterator(); iterator.hasNext(); ) { int id = iterator.nextInt(); idToIndex[id] = index; indexToId[index] = id; index++; } }
@Override public IntIterator iterator() { return collection.iterator(); } @Override
@Override public IntIterator iterator() { return IntIterators.unmodifiable(collection.iterator()); } @Override
/** * Creates a new array list and fills it with a given type-specific collection. * * @param c * a type-specific collection that will be used to fill the array * list. */ public IntArrayList(final IntCollection c) { this(c.size()); size = IntIterators.unwrap(c.iterator(), a); } /**
@Override public boolean removeAll(final IntCollection c) { boolean retVal = false; for (final IntIterator i = c.iterator(); i.hasNext();) if (rem(i.nextInt())) retVal = true; return retVal; } @Override
public boolean containsAll(IntCollection c) { final IntIterator i = c.iterator(); int n = c.size(); while (n-- != 0) if (!contains(i.nextInt())) return false; return true; }
public boolean containsAll(IntCollection c) { final IntIterator i = c.iterator(); int n = c.size(); while (n-- != 0) if (!contains(i.nextInt())) return false; return true; }
@Override public boolean addAll(final IntCollection c) { boolean retVal = false; for (final IntIterator i = c.iterator(); i.hasNext();) if (add(i.nextInt())) retVal = true; return retVal; } @Override
@Override public boolean containsAll(final IntCollection c) { for (final IntIterator i = c.iterator(); i.hasNext();) if (!contains(i.nextInt())) return false; return true; } @Override
public boolean containsAll(IntCollection c) { final IntIterator i = c.iterator(); int n = c.size(); while(n-- != 0) if (!contains(i.nextInt())) return false; return true; }
@Override public boolean addAll(int index, final IntCollection c) { ensureIndex(index); int n = c.size(); if (n == 0) return false; grow(size + n); if (index != size) System.arraycopy(a, index, a, index + n, size - index); final IntIterator i = c.iterator(); size += n; while (n-- != 0) a[index++] = i.nextInt(); assert size <= a.length; return true; } @Override
private int findSlotForPlayer(UUID playerUUID) { int targetSlot = -1; for (IntIterator iterator = skinUuidToSlotMap.get(playerUUID).iterator(); iterator.hasNext(); ) { int i = iterator.nextInt(); if (clientUuid[i] == fakePlayerUUIDs[i]) { targetSlot = i; break; } } if (targetSlot == -1) { for (int i = size - 1; i >= 0; i--) { if (clientUuid[i] == fakePlayerUUIDs[i]) { targetSlot = i; break; } } } if (targetSlot == -1) { throw new IllegalStateException("Not enough slots in tab list."); } return targetSlot; }
/** * Remove from this collection all elements which satisfy the given predicate. * * @param filter * a predicate which returns {@code true} for elements to be removed. * @see Collection#removeIf(java.util.function.Predicate) * @return {@code true} if any elements were removed. */ @SuppressWarnings("overloads") default boolean removeIf(final java.util.function.IntPredicate filter) { java.util.Objects.requireNonNull(filter); boolean removed = false; final IntIterator each = iterator(); while (each.hasNext()) { if (filter.test(each.nextInt())) { each.remove(); removed = true; } } return removed; } /**
public SortedDimensionDictionary(List<String> idToValue, int length) { Object2IntSortedMap<String> sortedMap = new Object2IntRBTreeMap<>(); for (int id = 0; id < length; id++) { sortedMap.put(idToValue.get(id), id); } this.sortedVals = Lists.newArrayList(sortedMap.keySet()); this.idToIndex = new int[length]; this.indexToId = new int[length]; int index = 0; for (IntIterator iterator = sortedMap.values().iterator(); iterator.hasNext();) { int id = iterator.nextInt(); idToIndex[id] = index; indexToId[index] = id; index++; } }
/** * Creates a new big-array big list and fills it with a given type-specific * collection. * * @param c * a type-specific collection that will be used to fill the array * list. */ public IntBigArrayBigList(final IntCollection c) { this(c.size()); for (IntIterator i = c.iterator(); i.hasNext();) add(i.nextInt()); } /**
@Override public boolean addAll(int index, final IntCollection c) { ensureIndex(index); final IntIterator i = c.iterator(); final boolean retVal = i.hasNext(); while (i.hasNext()) add(index++, i.nextInt()); return retVal; } /**
public SortedDimensionDictionary(List<String> idToValue, int length) { Object2IntSortedMap<String> sortedMap = new Object2IntRBTreeMap<>(Comparators.naturalNullsFirst()); for (int id = 0; id < length; id++) { String value = idToValue.get(id); sortedMap.put(value, id); } this.sortedVals = Lists.newArrayList(sortedMap.keySet()); this.idToIndex = new int[length]; this.indexToId = new int[length]; int index = 0; for (IntIterator iterator = sortedMap.values().iterator(); iterator.hasNext(); ) { int id = iterator.nextInt(); idToIndex[id] = index; indexToId[index] = id; index++; } }
@Nullable public static <T> T getWeightedRandom(Random random, Object2IntMap<T> choices) { long i = 0; IntCollection ints = choices.values(); for (IntIterator iterator = ints.iterator(); iterator.hasNext(); ) { int x = iterator.nextInt(); i += x; } i = getRandomLong(random, 0, i); for (Object2IntMap.Entry<T> entry : choices.object2IntEntrySet()) { i -= entry.getIntValue(); if (i < 0) { return entry.getKey(); } } return null; }
static public int[] argmax2(float[] scores, IntCollection labels) { if (labels == null || labels.isEmpty()) return argmax2(scores); IntIterator it = labels.iterator(); if (labels.size() < 2) return new int[]{it.nextInt(),-1}; int[] max = {it.nextInt(), it.nextInt()}; if (scores[max[0]] < scores[max[1]]) DSUtils.swap(max, 0, 1); while (it.hasNext()) { int i = it.nextInt(); if (scores[max[0]] < scores[i]) { max[1] = max[0]; max[0] = i; } else if (scores[max[1]] < scores[i]) max[1] = i; } return max; } }
static public int[] argmax2(float[] scores, IntCollection labels) { if (labels == null || labels.isEmpty()) return argmax2(scores); IntIterator it = labels.iterator(); if (labels.size() < 2) return new int[]{it.nextInt(),-1}; int[] max = {it.nextInt(), it.nextInt()}; if (scores[max[0]] < scores[max[1]]) DSUtils.swap(max, 0, 1); while (it.hasNext()) { int i = it.nextInt(); if (scores[max[0]] < scores[i]) { max[1] = max[0]; max[0] = i; } else if (scores[max[1]] < scores[i]) max[1] = i; } return max; } }