Java Code Examples for it.unimi.dsi.fastutil.longs.LongIterator#nextLong()
The following examples show how to use
it.unimi.dsi.fastutil.longs.LongIterator#nextLong() .
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 collection 必须是可修改的集合 * @param predicate 过滤条件,为真的删除 * @param then 元素删除之后执行的逻辑 * @return 删除的元素数量 */ public static int removeIfAndThen(LongCollection collection, LongPredicate predicate, LongConsumer then) { if (collection.size() == 0) { return 0; } final LongIterator itr = collection.iterator(); long value; int removeNum = 0; while (itr.hasNext()) { value = itr.nextLong(); if (predicate.test(value)) { itr.remove(); removeNum++; then.accept(value); } } return removeNum; }
Example 2
Source File: TransactionManager.java From phoenix-tephra with Apache License 2.0 | 6 votes |
private boolean doTruncateInvalidTxBefore(long time) throws InvalidTruncateTimeException { LOG.info("Removing tx ids before {} from invalid list", time); long truncateWp = time * TxConstants.MAX_TX_PER_MS; // Check if there any in-progress transactions started earlier than truncate time if (inProgress.lowerKey(truncateWp) != null) { throw new InvalidTruncateTimeException("Transactions started earlier than " + time + " are in-progress"); } // Find all invalid transactions earlier than truncateWp LongSet toTruncate = new LongArraySet(); LongIterator it = invalidTxList.toRawList().iterator(); while (it.hasNext()) { long wp = it.nextLong(); if (wp < truncateWp) { toTruncate.add(wp); } } LOG.info("Removing tx ids {} from invalid list", toTruncate); return invalidTxList.removeAll(toTruncate); }
Example 3
Source File: PageRank.java From GraphJet with Apache License 2.0 | 6 votes |
/** * Runs PageRank, either until the max number of iterations has been reached or the L1 norm of * the difference between PageRank vectors drops below the tolerance. * * @return number of iterations that was actually run */ public int run() { LongArrayList noOuts = new LongArrayList(); LongIterator iter = nodes.iterator(); while (iter.hasNext()) { long v = iter.nextLong(); if (graph.getOutDegree(v) == 0) { noOuts.add(v); } } double dampingAmount = (1.0 - dampingFactor) / nodeCount; prVector = new double[(int) (maxNodeId + 1)]; nodes.forEach(v -> prVector[(int) (long) v] = 1.0 / nodeCount); int i = 0; while (i < this.maxIterations && normL1 > tolerance) { iterate(dampingAmount, noOuts); i++; } return i; }
Example 4
Source File: MultiThreadedPageRank.java From GraphJet with Apache License 2.0 | 6 votes |
@Override public void run() { // Each thread runs on its own partition of the nodes, distributing PageRank mass for the // nodes that were assigned to it. final LongIterator iter = nodes.iterator(); while (iter.hasNext()) { long v = iter.nextLong(); int outDegree = graph.getOutDegree(v); if (outDegree > 0) { double outWeight = dampingFactor * prVector.get((int) v) / outDegree; EdgeIterator edges = graph.getOutEdges(v); while (edges.hasNext()) { int nbr = (int) edges.nextLong(); // Note that getAndAdd is implemented as an atomic operation with CAS, so // it's fine to have concurrent accesses to the PageRank vector. nextPR.getAndAdd(nbr, outWeight); } } nextPR.getAndAdd((int) v, mass); } latch.countDown(); }
Example 5
Source File: InstantColumn.java From tablesaw with Apache License 2.0 | 5 votes |
@Override public InstantColumn removeMissing() { InstantColumn noMissing = emptyCopy(); LongIterator iterator = longIterator(); while (iterator.hasNext()) { long i = iterator.nextLong(); if (!valueIsMissing(i)) { noMissing.appendInternal(i); } } return noMissing; }
Example 6
Source File: DateTimeColumn.java From tablesaw with Apache License 2.0 | 5 votes |
@Override public DateTimeColumn removeMissing() { DateTimeColumn noMissing = emptyCopy(); LongIterator iterator = longIterator(); while (iterator.hasNext()) { long i = iterator.nextLong(); if (!valueIsMissing(i)) { noMissing.appendInternal(i); } } return noMissing; }
Example 7
Source File: PageRank.java From GraphJet with Apache License 2.0 | 5 votes |
private void iterate(double dampingAmount, LongArrayList noOuts) { double nextPR[] = new double[(int) (maxNodeId + 1)]; // PageRank vector after the iteration. // First compute how much mass is trapped at the dangling nodes. double dangleSum = 0.0; LongIterator iter = noOuts.iterator(); while (iter.hasNext()) { dangleSum += prVector[(int) iter.nextLong()]; } dangleSum = dampingFactor * dangleSum / nodeCount; // Distribute PageRank mass. iter = nodes.iterator(); while (iter.hasNext()) { long v = iter.nextLong(); int outDegree = graph.getOutDegree(v); if (outDegree > 0) { double outWeight = dampingFactor * prVector[(int) v] / outDegree; EdgeIterator edges = graph.getOutEdges(v); while (edges.hasNext()) { int nbr = (int) edges.nextLong(); nextPR[nbr] += outWeight; } } nextPR[(int) v] += dampingAmount + dangleSum; } normL1 = computeL1Norm(prVector, nextPR); prVector = nextPR; }
Example 8
Source File: InstantColumn.java From tablesaw with Apache License 2.0 | 5 votes |
@Override public InstantColumn removeMissing() { InstantColumn noMissing = emptyCopy(); LongIterator iterator = longIterator(); while (iterator.hasNext()) { long i = iterator.nextLong(); if (!valueIsMissing(i)) { noMissing.appendInternal(i); } } return noMissing; }
Example 9
Source File: DateTimeColumn.java From tablesaw with Apache License 2.0 | 5 votes |
@Override public DateTimeColumn removeMissing() { DateTimeColumn noMissing = emptyCopy(); LongIterator iterator = longIterator(); while (iterator.hasNext()) { long i = iterator.nextLong(); if (!valueIsMissing(i)) { noMissing.appendInternal(i); } } return noMissing; }
Example 10
Source File: ThrottleTracker.java From ProtocolSupport with GNU Affero General Public License v3.0 | 5 votes |
public static boolean throttle(InetAddress address) { synchronized (tracker) { long ctime = Utils.currentTimeMillisFromNanoTime(); LongIterator iterator = tracker.values().iterator(); while (iterator.hasNext()) { if (iterator.nextLong() < ctime) { iterator.remove(); } } long ret = tracker.put(address, ctime + time); return ret != tracker.defaultReturnValue(); } }
Example 11
Source File: Player.java From Nukkit with GNU General Public License v3.0 | 4 votes |
protected boolean orderChunks() { if (!this.connected) { return false; } Timings.playerChunkOrderTimer.startTiming(); this.nextChunkOrderRun = 200; loadQueue.clear(); Long2ObjectOpenHashMap<Boolean> lastChunk = new Long2ObjectOpenHashMap<>(this.usedChunks); int centerX = (int) this.x >> 4; int centerZ = (int) this.z >> 4; int radius = spawned ? this.chunkRadius : (int) Math.ceil(Math.sqrt(spawnThreshold)); int radiusSqr = radius * radius; long index; for (int x = 0; x <= radius; x++) { int xx = x * x; for (int z = 0; z <= x; z++) { int distanceSqr = xx + z * z; if (distanceSqr > radiusSqr) continue; /* Top right quadrant */ if(this.usedChunks.get(index = Level.chunkHash(centerX + x, centerZ + z)) != Boolean.TRUE) { this.loadQueue.put(index, Boolean.TRUE); } lastChunk.remove(index); /* Top left quadrant */ if(this.usedChunks.get(index = Level.chunkHash(centerX - x - 1, centerZ + z)) != Boolean.TRUE) { this.loadQueue.put(index, Boolean.TRUE); } lastChunk.remove(index); /* Bottom right quadrant */ if(this.usedChunks.get(index = Level.chunkHash(centerX + x, centerZ - z - 1)) != Boolean.TRUE) { this.loadQueue.put(index, Boolean.TRUE); } lastChunk.remove(index); /* Bottom left quadrant */ if(this.usedChunks.get(index = Level.chunkHash(centerX - x - 1, centerZ - z - 1)) != Boolean.TRUE) { this.loadQueue.put(index, Boolean.TRUE); } lastChunk.remove(index); if(x != z){ /* Top right quadrant mirror */ if(this.usedChunks.get(index = Level.chunkHash(centerX + z, centerZ + x)) != Boolean.TRUE) { this.loadQueue.put(index, Boolean.TRUE); } lastChunk.remove(index); /* Top left quadrant mirror */ if(this.usedChunks.get(index = Level.chunkHash(centerX - z - 1, centerZ + x)) != Boolean.TRUE) { this.loadQueue.put(index, Boolean.TRUE); } lastChunk.remove(index); /* Bottom right quadrant mirror */ if(this.usedChunks.get(index = Level.chunkHash(centerX + z, centerZ - x - 1)) != Boolean.TRUE) { this.loadQueue.put(index, Boolean.TRUE); } lastChunk.remove(index); /* Bottom left quadrant mirror */ if(this.usedChunks.get(index = Level.chunkHash(centerX - z - 1, centerZ - x - 1)) != Boolean.TRUE) { this.loadQueue.put(index, Boolean.TRUE); } lastChunk.remove(index); } } } LongIterator keys = lastChunk.keySet().iterator(); while (keys.hasNext()) { index = keys.nextLong(); this.unloadChunk(Level.getHashX(index), Level.getHashZ(index)); } if (!loadQueue.isEmpty()) { NetworkChunkPublisherUpdatePacket packet = new NetworkChunkPublisherUpdatePacket(); packet.position = this.asBlockVector3(); packet.radius = viewDistance << 4; this.dataPacket(packet); } Timings.playerChunkOrderTimer.stopTiming(); return true; }
Example 12
Source File: Player.java From Nukkit with GNU General Public License v3.0 | 4 votes |
protected boolean orderChunks() { if (!this.connected) { return false; } Timings.playerChunkOrderTimer.startTiming(); this.nextChunkOrderRun = 200; loadQueue.clear(); Long2ObjectOpenHashMap<Boolean> lastChunk = new Long2ObjectOpenHashMap<>(this.usedChunks); int centerX = (int) this.x >> 4; int centerZ = (int) this.z >> 4; int radius = spawned ? this.chunkRadius : (int) Math.ceil(Math.sqrt(spawnThreshold)); int radiusSqr = radius * radius; long index; for (int x = 0; x <= radius; x++) { int xx = x * x; for (int z = 0; z <= x; z++) { int distanceSqr = xx + z * z; if (distanceSqr > radiusSqr) continue; /* Top right quadrant */ if(this.usedChunks.get(index = Level.chunkHash(centerX + x, centerZ + z)) != Boolean.TRUE) { this.loadQueue.put(index, Boolean.TRUE); } lastChunk.remove(index); /* Top left quadrant */ if(this.usedChunks.get(index = Level.chunkHash(centerX - x - 1, centerZ + z)) != Boolean.TRUE) { this.loadQueue.put(index, Boolean.TRUE); } lastChunk.remove(index); /* Bottom right quadrant */ if(this.usedChunks.get(index = Level.chunkHash(centerX + x, centerZ - z - 1)) != Boolean.TRUE) { this.loadQueue.put(index, Boolean.TRUE); } lastChunk.remove(index); /* Bottom left quadrant */ if(this.usedChunks.get(index = Level.chunkHash(centerX - x - 1, centerZ - z - 1)) != Boolean.TRUE) { this.loadQueue.put(index, Boolean.TRUE); } lastChunk.remove(index); if(x != z){ /* Top right quadrant mirror */ if(this.usedChunks.get(index = Level.chunkHash(centerX + z, centerZ + x)) != Boolean.TRUE) { this.loadQueue.put(index, Boolean.TRUE); } lastChunk.remove(index); /* Top left quadrant mirror */ if(this.usedChunks.get(index = Level.chunkHash(centerX - z - 1, centerZ + x)) != Boolean.TRUE) { this.loadQueue.put(index, Boolean.TRUE); } lastChunk.remove(index); /* Bottom right quadrant mirror */ if(this.usedChunks.get(index = Level.chunkHash(centerX + z, centerZ - x - 1)) != Boolean.TRUE) { this.loadQueue.put(index, Boolean.TRUE); } lastChunk.remove(index); /* Bottom left quadrant mirror */ if(this.usedChunks.get(index = Level.chunkHash(centerX - z - 1, centerZ - x - 1)) != Boolean.TRUE) { this.loadQueue.put(index, Boolean.TRUE); } lastChunk.remove(index); } } } LongIterator keys = lastChunk.keySet().iterator(); while (keys.hasNext()) { index = keys.nextLong(); this.unloadChunk(Level.getHashX(index), Level.getHashZ(index)); } Timings.playerChunkOrderTimer.stopTiming(); return true; }