Java Code Examples for it.unimi.dsi.fastutil.ints.Int2ObjectMap#Entry
The following examples show how to use
it.unimi.dsi.fastutil.ints.Int2ObjectMap#Entry .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FastCollectionsUtils.java From fastjgame with Apache License 2.0 | 6 votes |
/** * 移除map中符合条件的元素,并对删除的元素执行后续的操作 * * @param map 必须是可修改的map * @param predicate 过滤条件,为真的删除 * @param then 元素删除之后执行的逻辑 * @param <V> the type of value * @return 删除的元素数量 */ public static <V> int removeIfAndThen(final Int2ObjectMap<V> map, final IntObjPredicate<? super V> predicate, IntObjConsumer<V> then) { if (map.size() == 0) { return 0; } ObjectIterator<Int2ObjectMap.Entry<V>> itr = map.int2ObjectEntrySet().iterator(); int removeNum = 0; Int2ObjectMap.Entry<V> entry; int k; V v; while (itr.hasNext()) { entry = itr.next(); k = entry.getIntKey(); v = entry.getValue(); if (predicate.test(k, v)) { itr.remove(); removeNum++; then.accept(k, v); } } return removeNum; }
Example 2
Source File: ArrayMap.java From Kettle with GNU General Public License v3.0 | 6 votes |
@Override public ObjectSet<Int2ObjectMap.Entry<V>> int2ObjectEntrySet() { return entrySet != null ? entrySet : (entrySet = new AbstractObjectSet<Int2ObjectMap.Entry<V>>() { @Override @Nonnull public ObjectIterator<Int2ObjectMap.Entry<V>> iterator() { return new EntryIterator<Int2ObjectMap.Entry<V>>() { @Override public Int2ObjectMap.Entry<V> next() { return nextEntry(); } }; } @Override public int size() { return size; } }); }
Example 3
Source File: TextureUtil.java From FastAsyncWorldedit with GNU General Public License v3.0 | 6 votes |
protected void calculateLayerArrays() { Int2ObjectOpenHashMap<char[]> colorLayerMap = new Int2ObjectOpenHashMap<>(); for (int i = 0; i < validBlockIds.length; i++) { int color = validColors[i]; int combined = validBlockIds[i]; if (hasAlpha(color)) { for (int j = 0; j < validBlockIds.length; j++) { int colorOther = validColors[j]; if (!hasAlpha(colorOther)) { int combinedOther = validBlockIds[j]; int combinedColor = combineTransparency(color, colorOther); colorLayerMap.put(combinedColor, new char[]{(char) combined, (char) combinedOther}); } } } } this.validLayerColors = new int[colorLayerMap.size()]; this.validLayerBlocks = new char[colorLayerMap.size()][]; int index = 0; for (Int2ObjectMap.Entry<char[]> entry : colorLayerMap.int2ObjectEntrySet()) { validLayerColors[index] = entry.getIntKey(); validLayerBlocks[index++] = entry.getValue(); } }
Example 4
Source File: DioriteRandomUtils.java From Diorite with MIT License | 6 votes |
@Nullable public static <T> T getWeightedRandomReversed(Random random, Int2ObjectMap<T> choices) { long i = 0; IntSet ints = choices.keySet(); for (IntIterator iterator = ints.iterator(); iterator.hasNext(); ) { int x = iterator.nextInt(); i += x; } i = getRandomLong(random, 0, i); for (Int2ObjectMap.Entry<T> entry : choices.int2ObjectEntrySet()) { i -= entry.getIntKey(); if (i < 0) { return entry.getValue(); } } return null; }
Example 5
Source File: BlockVectorSet.java From FastAsyncWorldedit with GNU General Public License v3.0 | 6 votes |
public Vector get(int index) { int count = 0; ObjectIterator<Int2ObjectMap.Entry<LocalBlockVectorSet>> iter = localSets.int2ObjectEntrySet().iterator(); while (iter.hasNext()) { Int2ObjectMap.Entry<LocalBlockVectorSet> entry = iter.next(); LocalBlockVectorSet set = entry.getValue(); int size = set.size(); int newSize = count + size; if (newSize > index) { int localIndex = index - count; Vector pos = set.getIndex(localIndex); if (pos != null) { int pair = entry.getIntKey(); int cx = MathMan.unpairX(pair); int cz = MathMan.unpairY(pair); pos.mutX((cx << 11) + pos.getBlockX()); pos.mutZ((cz << 11) + pos.getBlockZ()); return pos; } } count += newSize; } return null; }
Example 6
Source File: ArrayMap.java From Kettle with GNU General Public License v3.0 | 5 votes |
Int2ObjectMap.Entry<V> nextEntry() { AtomicReferenceArray<V> values = ArrayMap.this.values; while (index < values.length()) { int key = index++; V value = values.get(key); if (value != null) { return new Entry(key, value); } } throw new NoSuchElementException(); }
Example 7
Source File: SparseTable.java From jstarcraft-ai with Apache License 2.0 | 5 votes |
@Override public SparseTable<T> setValues(T value) { for (Int2ObjectMap.Entry<T> term : cells.int2ObjectEntrySet()) { term.setValue(value); } return this; }
Example 8
Source File: MCAFile.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
public boolean isModified() { if (isDeleted()) { return true; } synchronized (chunks) { for (Int2ObjectMap.Entry<MCAChunk> entry : chunks.int2ObjectEntrySet()) { MCAChunk chunk = entry.getValue(); if (chunk.isModified() || chunk.isDeleted()) { return true; } } } return false; }
Example 9
Source File: Fastutil.java From incubator-hivemall with Apache License 2.0 | 5 votes |
@Nonnull public static <V> ObjectIterable<Int2ObjectMap.Entry<V>> fastIterable( @Nonnull final Int2ObjectMap<V> map) { final ObjectSet<Int2ObjectMap.Entry<V>> entries = map.int2ObjectEntrySet(); return entries instanceof Int2ObjectMap.FastEntrySet ? new ObjectIterable<Int2ObjectMap.Entry<V>>() { public ObjectIterator<Int2ObjectMap.Entry<V>> iterator() { return ((Int2ObjectMap.FastEntrySet<V>) entries).fastIterator(); } } : entries; }
Example 10
Source File: BlockVectorSet.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@Override public Iterator<Vector> iterator() { final ObjectIterator<Int2ObjectMap.Entry<LocalBlockVectorSet>> entries = localSets.int2ObjectEntrySet().iterator(); if (!entries.hasNext()) { return new ArrayList<Vector>().iterator(); } return new Iterator<Vector>() { Int2ObjectMap.Entry<LocalBlockVectorSet> entry = entries.next(); Iterator<Vector> entryIter = entry.getValue().iterator(); MutableBlockVector mutable = new MutableBlockVector(); @Override public void remove() { entryIter.remove(); } @Override public boolean hasNext() { return entryIter.hasNext() || entries.hasNext(); } @Override public Vector next() { while (!entryIter.hasNext()) { if (!entries.hasNext()) { throw new NoSuchElementException("End of iterator"); } entry = entries.next(); entryIter = entry.getValue().iterator(); } Vector localPos = entryIter.next(); int pair = entry.getIntKey(); int cx = MathMan.unpairX(pair); int cz = MathMan.unpairY(pair); return mutable.setComponents((cx << 11) + localPos.getBlockX(), localPos.getBlockY(), (cz << 11) + localPos.getBlockZ()); } }; }
Example 11
Source File: BlockVectorSet.java From FastAsyncWorldedit with GNU General Public License v3.0 | 5 votes |
@Override public boolean isEmpty() { for (Int2ObjectMap.Entry<LocalBlockVectorSet> entry : localSets.int2ObjectEntrySet()) { if (!entry.getValue().isEmpty()) { return false; } } return true; }
Example 12
Source File: IntDictionaryMap.java From tablesaw with Apache License 2.0 | 4 votes |
ObjectSet<Int2ObjectMap.Entry<String>> getKeyValueEntries() { return keyToValue.int2ObjectEntrySet(); }
Example 13
Source File: SortedPositionLinks.java From presto with Apache License 2.0 | 4 votes |
@Override public Factory build() { ArrayPositionLinks.FactoryBuilder arrayPositionLinksFactoryBuilder = ArrayPositionLinks.builder(size); int[][] sortedPositionLinks = new int[size][]; for (Int2ObjectMap.Entry<IntArrayList> entry : positionLinks.int2ObjectEntrySet()) { int key = entry.getIntKey(); IntArrayList positions = entry.getValue(); positions.sort(comparator); sortedPositionLinks[key] = new int[positions.size()]; for (int i = 0; i < positions.size(); i++) { sortedPositionLinks[key][i] = positions.get(i); } // ArrayPositionsLinks.Builder::link builds position links from // tail to head, so we must add them in descending order to have // smallest element as a head for (int i = positions.size() - 2; i >= 0; i--) { arrayPositionLinksFactoryBuilder.link(positions.get(i), positions.get(i + 1)); } // add link from starting position to position links chain if (!positions.isEmpty()) { arrayPositionLinksFactoryBuilder.link(key, positions.get(0)); } } Factory arrayPositionLinksFactory = arrayPositionLinksFactoryBuilder.build(); return new Factory() { @Override public PositionLinks create(List<JoinFilterFunction> searchFunctions) { return new SortedPositionLinks( arrayPositionLinksFactory.create(ImmutableList.of()), sortedPositionLinks, searchFunctions); } @Override public long checksum() { // For spill/unspill state restoration, sorted position links do not matter return arrayPositionLinksFactory.checksum(); } }; }
Example 14
Source File: TopSecondDegreeByCountTweetMetadataRecsGenerator.java From GraphJet with Apache License 2.0 | 4 votes |
/** * Return tweet metadata recommendations, like hashtags and urls. * * @param request topSecondDegreeByCount request * @param nodeInfoList a list of node info containing engagement social proof and weights * @param recommendationType the recommendation type to return, like hashtag and url * @return a list of recommendations of the recommendation type */ public static List<RecommendationInfo> generateTweetMetadataRecs( TopSecondDegreeByCountRequestForTweet request, List<NodeInfo> nodeInfoList, RecommendationType recommendationType ) { Int2ObjectMap<TweetMetadataRecommendationInfo> visitedMetadata = null; List<RecommendationInfo> results = new ArrayList<>(); for (NodeInfo nodeInfo : nodeInfoList) { // Remove unfavorited edges, and discard the nodeInfo if it no longer has social proofs boolean isNodeModified = NodeInfoHelper.removeUnfavoritedSocialProofs(nodeInfo); if (isNodeModified && !NodeInfoHelper.nodeInfoHasValidSocialProofs(nodeInfo)) { continue; } int[] metadata = nodeInfo.getNodeMetadata(recommendationType.getValue()); if (metadata == null) { continue; } if (visitedMetadata == null) { visitedMetadata = new Int2ObjectOpenHashMap<>(); } for (int j = 0; j < metadata.length; j++) { TweetMetadataRecommendationInfo recommendationInfo = visitedMetadata.get(metadata[j]); if (recommendationInfo == null) { recommendationInfo = new TweetMetadataRecommendationInfo( metadata[j], RecommendationType.at(recommendationType.getValue()), 0, new HashMap<Byte, Map<Long, LongList>>() ); } recommendationInfo.addToWeight(nodeInfo.getWeight()); addToSocialProof( nodeInfo, recommendationInfo, request.getMaxUserSocialProofSize(), request.getMaxTweetSocialProofSize() ); visitedMetadata.put(metadata[j], recommendationInfo); } } if (visitedMetadata != null) { int maxNumResults = GeneratorHelper.getMaxNumResults(request, recommendationType); int minUserSocialProofSize = GeneratorHelper.getMinUserSocialProofSize(request, recommendationType); List<TweetMetadataRecommendationInfo> filtered = null; for (Int2ObjectMap.Entry<TweetMetadataRecommendationInfo> entry : visitedMetadata.int2ObjectEntrySet()) { // handling one specific rule related to metadata recommendations. if (isLessThanMinUserSocialProofSize( entry.getValue().getSocialProof(), minUserSocialProofSize)) { continue; } if (filtered == null) { filtered = new ArrayList<>(); } filtered.add(entry.getValue()); } if (filtered != null) { // sort the list of TweetMetadataRecommendationInfo in ascending order // according to their weights Collections.sort(filtered); int toIndex = Math.min(maxNumResults, filtered.size()); for (int j = 0; j < toIndex; j++) { results.add(filtered.get(j)); } } } return results; }
Example 15
Source File: IntDictionaryMap.java From tablesaw with Apache License 2.0 | 4 votes |
ObjectSet<Int2ObjectMap.Entry<String>> getKeyValueEntries() { return keyToValue.int2ObjectEntrySet(); }
Example 16
Source File: SlimUDTF.java From incubator-hivemall with Apache License 2.0 | 4 votes |
private void recordTrainingInput(final int itemI, @Nonnull final Int2ObjectMap<Int2FloatMap> knnItems, final int numKNNItems) throws HiveException { ByteBuffer buf = this._inputBuf; NioStatefulSegment dst = this._fileIO; if (buf == null) { // invoke only at task node (initialize is also invoked in compilation) final File file; try { file = File.createTempFile("hivemall_slim", ".sgmt"); // to save KNN data file.deleteOnExit(); if (!file.canWrite()) { throw new UDFArgumentException( "Cannot write a temporary file: " + file.getAbsolutePath()); } } catch (IOException ioe) { throw new UDFArgumentException(ioe); } this._inputBuf = buf = ByteBuffer.allocateDirect(8 * 1024 * 1024); // 8MB this._fileIO = dst = new NioStatefulSegment(file, false); } int recordBytes = SizeOf.INT + SizeOf.INT + SizeOf.INT * 2 * knnItems.size() + (SizeOf.INT + SizeOf.FLOAT) * numKNNItems; int requiredBytes = SizeOf.INT + recordBytes; // need to allocate space for "recordBytes" itself int remain = buf.remaining(); if (remain < requiredBytes) { writeBuffer(buf, dst); } buf.putInt(recordBytes); buf.putInt(itemI); buf.putInt(knnItems.size()); for (Int2ObjectMap.Entry<Int2FloatMap> e1 : Fastutil.fastIterable(knnItems)) { int user = e1.getIntKey(); buf.putInt(user); Int2FloatMap ru = e1.getValue(); buf.putInt(ru.size()); for (Int2FloatMap.Entry e2 : Fastutil.fastIterable(ru)) { buf.putInt(e2.getIntKey()); buf.putFloat(e2.getFloatValue()); } } }
Example 17
Source File: ProtocolRegistry.java From ViaVersion with MIT License | 4 votes |
/** * Calculate a path to get from an input protocol to the servers protocol. * * @param current The current items in the path * @param clientVersion The current input version * @param serverVersion The desired output version * @return The path which has been generated, null if failed. */ @Nullable private static List<Pair<Integer, Protocol>> getProtocolPath(List<Pair<Integer, Protocol>> current, int clientVersion, int serverVersion) { if (clientVersion == serverVersion) return null; // We're already there if (current.size() > 50) return null; // Fail safe, protocol too complicated. // First check if there is any protocols for this Int2ObjectMap<Protocol> inputMap = registryMap.get(clientVersion); if (inputMap == null) { return null; // Not supported } // Next check there isn't an obvious path Protocol protocol = inputMap.get(serverVersion); if (protocol != null) { current.add(new Pair<>(serverVersion, protocol)); return current; // Easy solution } // There might be a more advanced solution... So we'll see if any of the others can get us there List<Pair<Integer, Protocol>> shortest = null; for (Int2ObjectMap.Entry<Protocol> entry : inputMap.int2ObjectEntrySet()) { // Ensure it wasn't caught by the other loop if (entry.getIntKey() == (serverVersion)) continue; Pair<Integer, Protocol> pair = new Pair<>(entry.getIntKey(), entry.getValue()); // Ensure no recursion if (current.contains(pair)) continue; // Create a copy List<Pair<Integer, Protocol>> newCurrent = new ArrayList<>(current); newCurrent.add(pair); // Calculate the rest of the protocol using the current newCurrent = getProtocolPath(newCurrent, entry.getKey(), serverVersion); if (newCurrent != null) { // If it's shorter then choose it if (shortest == null || shortest.size() > newCurrent.size()) { shortest = newCurrent; } } } return shortest; // null if none found }