@Override public int[] removeAll(final ItemStack itemStack) { final ItemStackImplArray content = this.getArray(); if (itemStack == null) { return DioriteArrayUtils.EMPTY_INTS; } final IntCollection list = new IntArrayList(10); for (int i = 0, size = content.length(); i < size; i++) { final ItemStack item = content.get(i); if (Objects.equals(item, itemStack)) { content.compareAndSet(i, ItemStackImpl.wrap(item), null); list.add(i); } } if (list.isEmpty()) { return DioriteArrayUtils.EMPTY_INTS; } return list.toIntArray(); }
@Override public int[] removeAllFromEnd(final ItemStack itemStack) { final ItemStackImplArray content = this.getArray(); if (itemStack == null) { return DioriteArrayUtils.EMPTY_INTS; } final IntCollection list = new IntArrayList(10); for (int i = content.length() - 1; i >= 0; i--) { final ItemStack item = content.get(i); if (Objects.equals(item, itemStack)) { content.compareAndSet(i, ItemStackImpl.wrap(item), null); list.add(i); } } if (list.isEmpty()) { return DioriteArrayUtils.EMPTY_INTS; } return list.toIntArray(); }
@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; }
public IntCollection values() { if ( values == null ) values = new AbstractIntCollection () { public IntIterator iterator() { return new ValueIterator(); } public int size() { return size; } public boolean contains( int v ) { return containsValue( v ); } public void clear() { Int2IntOpenHashMap.this.clear(); } }; return values; }
@Override public int[] removeAll(final Material material, final boolean ignoreType) { final ItemStackImplArray content = this.getArray(); if (material == null) { return DioriteArrayUtils.EMPTY_INTS; } final IntCollection list = new IntArrayList(10); for (int i = 0, size = content.length(); i < size; i++) { final ItemStack item = content.get(i); if (item == null) { continue; } final Material mat = item.getMaterial(); if (ignoreType) { if ((material.ordinal() != mat.ordinal())) { continue; } } else if (! Objects.equals(mat, material)) { continue; } content.compareAndSet(i, ItemStackImpl.wrap(item), null); list.add(i); } if (list.isEmpty()) { return DioriteArrayUtils.EMPTY_INTS; } return list.toIntArray(); }
@Override public int[] removeAllFromEnd(final Material material, final boolean ignoreType) { final ItemStackImplArray content = this.getArray(); if (material == null) { return DioriteArrayUtils.EMPTY_INTS; } final IntCollection list = new IntArrayList(10); for (int i = content.length() - 1; i >= 0; i--) { final ItemStack item = content.get(i); if (item == null) { continue; } final Material mat = item.getMaterial(); if (ignoreType) { if ((material.ordinal() != mat.ordinal())) { continue; } } else if (! Objects.equals(mat, material)) { continue; } content.compareAndSet(i, ItemStackImpl.wrap(item), null); list.add(i); } if (list.isEmpty()) { return DioriteArrayUtils.EMPTY_INTS; } return list.toIntArray(); }
/** Returns a type-specific-set view of the values of this map. * * <P>The view is backed by the set returned by {@link #entrySet()}. Note that * <em>no attempt is made at caching the result of this method</em>, as this would * require adding some attributes that lightweight implementations would * not need. Subclasses may easily override this policy by calling * this method and caching the result, but implementors are encouraged to * write more efficient ad-hoc implementations. * * @return a set view of the values of this map; it may be safely cast to a type-specific interface. */ public IntCollection values() { return new AbstractIntCollection () { public boolean contains( final int k ) { return containsValue( k ); } public int size() { return AbstractInt2IntMap.this.size(); } public void clear() { AbstractInt2IntMap.this.clear(); } public IntIterator iterator() { return new AbstractIntIterator () { final ObjectIterator<Map.Entry<Integer,Integer>> i = entrySet().iterator(); public int nextInt() { return ((Int2IntMap.Entry )i.next()).getIntValue(); }; public boolean hasNext() { return i.hasNext(); } }; } }; }
public void remove(T key, int value) { IntCollection collection = map.get(key); if (collection != null) { collection.rem(value); if (collection.isEmpty()) { map.remove(key); } } }
public IntCollection values() { return valueToKey.values(); }
private int init(String graphId, URI uri) { INameNode nameNode = new RemoteNameNode(uri); int partCount = 0; try { for (URI u : nameNode.getDataNodes()) { if (URIHelper.isLocalURI(u)) { dataNode = DataNode.create(u); IntCollection partitions = dataNode.getLocalPartitions(graphId); int partId = partitions.iterator().nextInt(); // long loadS = System.currentTimeMillis(); partition = dataNode.loadLocalPartition(graphId, partId); //StatLogger.getInstance().log("PARTITION_LOAD," + partition.getId() + "," + (System.currentTimeMillis() - loadS)); for (int pid : nameNode.getPartitionDirectory().getPartitions(graphId)) { this.partList.add(pid); partCount++; } infoPrefix = "INFO,"+partition.getId() + ","; statePrefix = "STATE,"+partition.getId() + ","; perfPrefix = "PERF,"+partition.getId() + ","; break; } } if (partition == null) { throw new RuntimeException("UnExpected Error Graph " + graphId + "@" + uri + " does not exist"); } //long loadS = System.currentTimeMillis(); //StatLogger.getInstance().log("#SUBGRAPHS," + partition.getId() +","+ partition.size()); for (ISubgraph subgraph : partition) { subGraphMap.put(subgraph.getId(), subgraph); for (ITemplateVertex rv : subgraph.remoteVertices()) { subgraphToPartitionMap.put(rv.getRemoteSubgraphId(), rv.getRemotePartitionId()); } if (isInfoLoggingEnabled) logInfo(new Object[]{"TOPO.SG", "SG_ID", subgraph.getId(), "SG_V", subgraph.numVertices(), // TODO: rename subgraph.numVertices() as vertexCount() "SG_E", subgraph.numEdges(), "SG_RV", subgraph.numRemoteVertices() }); } //StatLogger.getInstance().log("#SUBGRAPHS_GOFS," + partition.getId() +","+ subGraphMap.size()); //StatLogger.getInstance().log("SUB_PART_MAP," + partition.getId() + "," + // (System.currentTimeMillis() - loadS)); int concurrentSubGraphSlots; if (FloeRuntimeEnvironment.getEnvironment().getSystemConfigParam(PARALLEL_WORKERS) != null) { concurrentSubGraphSlots = Integer.parseInt(FloeRuntimeEnvironment.getEnvironment(). getSystemConfigParam(PARALLEL_WORKERS)); } else { concurrentSubGraphSlots = (Runtime.getRuntime().availableProcessors() - 1) * 2; } concurrentSubGraphSlots = concurrentSubGraphSlots <= 0 ? 1 : concurrentSubGraphSlots; pool = new ForkJoinPool(concurrentSubGraphSlots); } catch (IOException e) { throw new RuntimeException(e); } return partCount; }
public boolean contains(T key, int value) { IntCollection collection = map.get(key); return collection != null && collection.contains(value); }
public IntCollection get(T key) { return map.getOrDefault(key, IntSets.EMPTY_SET); }
public void put(T key, int value) { IntCollection collection = map.computeIfAbsent(key, k -> new IntLinkedOpenHashSet(2, .75f)); collection.add(value); }
/** Returns a set view of the values contained in this map. * <P>Note that this specification strengthens the one given in {@link Map#values()}. * * @return a set view of the values contained in this map. * @see Map#values() */ IntCollection values();