Java Code Examples for it.unimi.dsi.fastutil.longs.LongSet#contains()
The following examples show how to use
it.unimi.dsi.fastutil.longs.LongSet#contains() .
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: InternalIdMapTestHelper.java From GraphJet with Apache License 2.0 | 6 votes |
public static KeyTestInfo generateRandomKeys(Random random, int maxNumKeys) { long[] keys = new long[maxNumKeys]; long[] nonKeys = new long[maxNumKeys]; LongSet keySet = new LongOpenHashBigSet(maxNumKeys); for (int i = 0; i < maxNumKeys; i++) { keys[i] = random.nextLong(); keySet.add(keys[i]); } for (int i = 0; i < maxNumKeys; i++) { long nonKey; do { nonKey = random.nextLong(); } while (keySet.contains(nonKey)); nonKeys[i] = nonKey; } return new KeyTestInfo(keys, nonKeys); }
Example 2
Source File: ArrayDistinctFunction.java From presto with Apache License 2.0 | 5 votes |
@SqlType("array(bigint)") public Block bigintDistinct(@SqlType("array(bigint)") Block array) { if (array.getPositionCount() == 0) { return array; } boolean containsNull = false; LongSet set = new LongOpenHashSet(array.getPositionCount()); int distinctCount = 0; if (pageBuilder.isFull()) { pageBuilder.reset(); } BlockBuilder distinctElementBlockBuilder = pageBuilder.getBlockBuilder(0); for (int i = 0; i < array.getPositionCount(); i++) { if (array.isNull(i)) { if (!containsNull) { containsNull = true; distinctElementBlockBuilder.appendNull(); distinctCount++; } continue; } long value = BIGINT.getLong(array, i); if (!set.contains(value)) { set.add(value); distinctCount++; BIGINT.appendTo(array, i, distinctElementBlockBuilder); } } pageBuilder.declarePositions(distinctCount); return distinctElementBlockBuilder.getRegion(distinctElementBlockBuilder.getPositionCount() - distinctCount, distinctCount); }
Example 3
Source File: AgreeSetGenerator.java From metanome-algorithms with Apache License 2.0 | 5 votes |
private void intersect(LongSet positions, LongSet indexSet) { LongSet toRemove = new LongArraySet(); for (long l : positions) { if (!indexSet.contains(l)) { toRemove.add(l); } } positions.removeAll(toRemove); }
Example 4
Source File: SocialProofGenerator.java From GraphJet with Apache License 2.0 | 5 votes |
/** * Collect social proofs for a given {@link SocialProofRequest}. * * @param leftSeedNodesWithWeight Engagement edges from these left nodes are iterated and collected * @param rightNodeIds Right nodes for which we want to generate social proofs * @param validSocialProofTypes Social proof types that we are interested in */ private void collectRightNodeInfo( Long2DoubleMap leftSeedNodesWithWeight, LongSet rightNodeIds, byte[] validSocialProofTypes) { ByteSet socialProofTypeSet = new ByteArraySet(validSocialProofTypes); // Iterate through the set of left node seeds with weights. // For each left node, go through its edges and collect the engagements on the right nodes for (Long2DoubleMap.Entry entry: leftSeedNodesWithWeight.long2DoubleEntrySet()) { long leftNode = entry.getLongKey(); EdgeIterator edgeIterator = leftIndexedBipartiteGraph.getLeftNodeEdges(leftNode); if (edgeIterator == null) { continue; } int numEdgePerNode = 0; double weight = entry.getDoubleValue(); seenEdgesPerNode.clear(); // Sequentially iterate through the latest MAX_EDGES_PER_NODE edges per node while (edgeIterator.hasNext() && numEdgePerNode++ < MAX_EDGES_PER_NODE) { long rightNode = idMask.restore(edgeIterator.nextLong()); byte edgeType = edgeIterator.currentEdgeType(); boolean hasSeenRightNodeFromEdge = seenEdgesPerNode.containsKey(rightNode) && seenEdgesPerNode.get(rightNode) == edgeType; boolean isValidEngagement = rightNodeIds.contains(rightNode) && socialProofTypeSet.contains(edgeType); if (hasSeenRightNodeFromEdge || !isValidEngagement) { continue; } updateVisitedRightNodes(leftNode, rightNode, edgeType, weight); } } }
Example 5
Source File: LeftRegularBipartiteGraphSegmentTest.java From GraphJet with Apache License 2.0 | 5 votes |
/** * Build a random left-regular bipartite graph of given left and right sizes. * * @param leftSize is the left hand size of the bipartite graph * @param rightSize is the right hand size of the bipartite graph * @param leftDegree is the degree of the left hand side * @param random is the random number generator to use for constructing the graph * @return a random bipartite graph */ public static LeftRegularBipartiteGraphSegment buildRandomLeftRegularBipartiteGraph( int leftSize, int rightSize, int leftDegree, Random random) { LeftRegularBipartiteGraphSegment leftRegularBipartiteGraphSegment = new LeftRegularBipartiteGraphSegment( leftSize / 2, leftDegree, rightSize / 2, leftSize / 2, 2.0, Integer.MAX_VALUE, new IdentityEdgeTypeMask(), new NullStatsReceiver()); LongSet addedIds = new LongOpenHashSet(leftDegree); for (int i = 0; i < leftSize; i++) { addedIds.clear(); for (int j = 0; j < leftDegree; j++) { long idToAdd; do { idToAdd = random.nextInt(rightSize); } while (addedIds.contains(idToAdd)); addedIds.add(idToAdd); leftRegularBipartiteGraphSegment.addEdge(i, idToAdd, (byte) 0); } } return leftRegularBipartiteGraphSegment; }
Example 6
Source File: ValueInTransformFunction.java From incubator-pinot with Apache License 2.0 | 5 votes |
private static long[] filterLongs(LongSet longSet, long[] source) { LongList longList = new LongArrayList(); for (long value : source) { if (longSet.contains(value)) { longList.add(value); } } if (longList.size() == source.length) { return source; } else { return longList.toLongArray(); } }
Example 7
Source File: BlockLeaves.java From Nukkit with GNU General Public License v3.0 | 4 votes |
private Boolean findLog(Block pos, LongSet visited, Integer distance, Integer check, BlockFace fromSide) { ++check; long index = Hash.hashBlock((int) pos.x, (int) pos.y, (int) pos.z); if (visited.contains(index)) return false; if (pos.getId() == WOOD || pos.getId() == WOOD2) return true; if ((pos.getId() == LEAVES || pos.getId() == LEAVES2) && distance <= 4) { visited.add(index); int down = pos.down().getId(); if (down == WOOD || down == WOOD2) { return true; } if (fromSide == null) { //North, East, South, West for (int side = 2; side <= 5; ++side) { if (this.findLog(pos.getSide(BlockFace.fromIndex(side)), visited, distance + 1, check, BlockFace.fromIndex(side))) return true; } } else { //No more loops switch (fromSide) { case NORTH: if (this.findLog(pos.getSide(BlockFace.NORTH), visited, distance + 1, check, fromSide)) return true; if (this.findLog(pos.getSide(BlockFace.WEST), visited, distance + 1, check, fromSide)) return true; if (this.findLog(pos.getSide(BlockFace.EAST), visited, distance + 1, check, fromSide)) return true; break; case SOUTH: if (this.findLog(pos.getSide(BlockFace.SOUTH), visited, distance + 1, check, fromSide)) return true; if (this.findLog(pos.getSide(BlockFace.WEST), visited, distance + 1, check, fromSide)) return true; if (this.findLog(pos.getSide(BlockFace.EAST), visited, distance + 1, check, fromSide)) return true; break; case WEST: if (this.findLog(pos.getSide(BlockFace.NORTH), visited, distance + 1, check, fromSide)) return true; if (this.findLog(pos.getSide(BlockFace.SOUTH), visited, distance + 1, check, fromSide)) return true; if (this.findLog(pos.getSide(BlockFace.WEST), visited, distance + 1, check, fromSide)) return true; case EAST: if (this.findLog(pos.getSide(BlockFace.NORTH), visited, distance + 1, check, fromSide)) return true; if (this.findLog(pos.getSide(BlockFace.SOUTH), visited, distance + 1, check, fromSide)) return true; if (this.findLog(pos.getSide(BlockFace.EAST), visited, distance + 1, check, fromSide)) return true; break; } } } return false; }