Java Code Examples for gnu.trove.set.TLongSet#add()
The following examples show how to use
gnu.trove.set.TLongSet#add() .
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: IdSelector.java From paintera with GNU General Public License v2.0 | 6 votes |
private void selectAllLabelMultisetType(final TLongSet allIds) { @SuppressWarnings("unchecked") final RandomAccessibleInterval<LabelMultisetType> data = (RandomAccessibleInterval<LabelMultisetType>) source.getDataSource(0, source.getNumMipmapLevels() - 1); final Cursor<LabelMultisetType> cursor = Views.iterable(data).cursor(); while (cursor.hasNext()) { final LabelMultisetType lmt = cursor.next(); for (final Entry<Label> entry : lmt.entrySet()) { final long id = entry.getElement().id(); if (foregroundCheck.test(id)) allIds.add(id); } } }
Example 2
Source File: SparseArrayWithLongCoding.java From morpheus-core with Apache License 2.0 | 6 votes |
@Override public Array<T> distinct(int limit) { final int capacity = limit < Integer.MAX_VALUE ? limit : 100; final TLongSet set = new TLongHashSet(capacity); final ArrayBuilder<T> builder = ArrayBuilder.of(capacity, type()); for (int i=0; i<length(); ++i) { final long code = getLong(i); if (set.add(code)) { final T value = getValue(i); builder.add(value); if (set.size() >= limit) { break; } } } return builder.toArray(); }
Example 3
Source File: SparseArrayOfLongs.java From morpheus-core with Apache License 2.0 | 6 votes |
@Override public final Array<Long> distinct(int limit) { final int capacity = limit < Integer.MAX_VALUE ? limit : 100; final TLongSet set = new TLongHashSet(capacity); final ArrayBuilder<Long> builder = ArrayBuilder.of(capacity, Long.class); for (int i=0; i<length(); ++i) { final long value = getLong(i); if (set.add(value)) { builder.addLong(value); if (set.size() >= limit) { break; } } } return builder.toArray(); }
Example 4
Source File: MappedArrayWithLongCoding.java From morpheus-core with Apache License 2.0 | 6 votes |
@Override public Array<T> distinct(int limit) { final int capacity = limit < Integer.MAX_VALUE ? limit : 100; final TLongSet set = new TLongHashSet(capacity); final ArrayBuilder<T> builder = ArrayBuilder.of(capacity, type()); for (int i=0; i<length(); ++i) { final long code = getLong(i); if (set.add(code)) { final T value = getValue(i); builder.add(value); if (set.size() >= limit) { break; } } } return builder.toArray(); }
Example 5
Source File: MappedArrayOfLongs.java From morpheus-core with Apache License 2.0 | 6 votes |
@Override public final Array<Long> distinct(int limit) { final int capacity = limit < Integer.MAX_VALUE ? limit : 100; final TLongSet set = new TLongHashSet(capacity); final ArrayBuilder<Long> builder = ArrayBuilder.of(capacity, Long.class); for (int i=0; i<length(); ++i) { final long value = getLong(i); if (set.add(value)) { builder.addLong(value); if (set.size() >= limit) { break; } } } return builder.toArray(); }
Example 6
Source File: DenseArrayWithLongCoding.java From morpheus-core with Apache License 2.0 | 6 votes |
@Override public Array<T> distinct(int limit) { final int capacity = limit < Integer.MAX_VALUE ? limit : 100; final TLongSet set = new TLongHashSet(capacity); final ArrayBuilder<T> builder = ArrayBuilder.of(capacity, type()); for (int i=0; i<length(); ++i) { final long code = getLong(i); if (set.add(code)) { final T value = getValue(i); builder.add(value); if (set.size() >= limit) { break; } } } return builder.toArray(); }
Example 7
Source File: DenseArrayOfLongs.java From morpheus-core with Apache License 2.0 | 6 votes |
@Override public final Array<Long> distinct(int limit) { final int capacity = limit < Integer.MAX_VALUE ? limit : 100; final TLongSet set = new TLongHashSet(capacity); final ArrayBuilder<Long> builder = ArrayBuilder.of(capacity, Long.class); for (int i=0; i<length(); ++i) { final long value = getLong(i); if (set.add(value)) { builder.addLong(value); if (set.size() >= limit) { break; } } } return builder.toArray(); }
Example 8
Source File: BlockVectors.java From PGM with GNU Affero General Public License v3.0 | 5 votes |
static TLongSet encodePosSet(Collection<?> vectors) { TLongSet encoded = new TLongHashSet(vectors.size()); for (Object o : vectors) { if (o instanceof BlockVector) { encoded.add(encodePos((BlockVector) o)); } } return encoded; }
Example 9
Source File: CachedGridEntry.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
public boolean populateChunk(World world) { MutableBlockPos blockPos = new MutableBlockPos(); boolean generatedAnything = false; for (OreDepositDefinition definition : oreBlocks.keySet()) { TLongList blockIndexList = oreBlocks.get(definition); TLongSet generatedBlocks = new TLongHashSet(); boolean generatedOreVein = false; for (int i = 0; i < blockIndexList.size(); i++) { long blockIndex = blockIndexList.get(i); int xyzValue = (int) (blockIndex >> 32); int blockX = (byte) xyzValue; int blockZ = (byte) (xyzValue >> 8); int blockY = (short) (xyzValue >> 16); int index = (int) blockIndex; blockPos.setPos(chunkX * 16 + blockX, blockY, chunkZ * 16 + blockZ); IBlockState currentState = world.getBlockState(blockPos); IBlockState newState; if (index == 0) { //it's primary ore block if (!definition.getGenerationPredicate().test(currentState, world, blockPos)) continue; //do not generate if predicate didn't match newState = definition.getBlockFiller().apply(currentState, world, blockPos, blockX, blockY, blockZ); } else { //it's populator-generated block with index VeinBufferPopulator populator = (VeinBufferPopulator) definition.getVeinPopulator(); newState = populator.getBlockByIndex(world, blockPos, index - 1); } //set flags as 16 to avoid observer updates loading neighbour chunks world.setBlockState(blockPos, newState, 16); generatedBlocks.add(Block.getStateId(newState)); generatedOreVein = true; generatedAnything = true; } if (generatedOreVein) { this.generatedBlocksSet.put(definition, generatedBlocks); this.generatedOres.add(definition); } } return generatedAnything; }
Example 10
Source File: IdSelector.java From paintera with GNU General Public License v2.0 | 5 votes |
private void selectAllPrimitiveType(final TLongSet allIds) { // TODO: run the operation in separate thread and allow to cancel it LOG.warn("Label data is stored as primitive type, looping over full resolution data to collect all ids -- SLOW"); final RandomAccessibleInterval<? extends IntegerType<?>> data = source.getDataSource(0, 0); final Cursor<? extends IntegerType<?>> cursor = Views.iterable(data).cursor(); while (cursor.hasNext()) { final long id = cursor.next().getIntegerLong(); if (foregroundCheck.test(id)) allIds.add(id); } }
Example 11
Source File: BlockUtils.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
public static TLongSet encodePosSet(Collection<?> vectors) { TLongSet encoded = new TLongHashSet(vectors.size()); for(Object o : vectors) { if(o instanceof BlockVector) { encoded.add(encodePos((BlockVector) o)); } } return encoded; }
Example 12
Source File: FallingBlocksMatchModule.java From PGM with GNU Affero General Public License v3.0 | 4 votes |
/** * Test if the given block is either self-supporting (doesn't match any falling rules) or is * adjacent to a supported block. The supported and unsupported arguments may contain the results * of previous completed searches. The blocks visited by this search will be added to one or the * other set depending on the final result. * * @param pos position of the block to test * @param supported set of blocks already known to be supported * @param unsupported set of blocks already known to be unsupported * @return true iff the given block is definitely supported */ private boolean isSupported(long pos, TLongSet supported, TLongSet unsupported) throws MaxSearchVisitsExceeded { World world = match.getWorld(); LongDeque queue = new LongDeque(); TLongSet visited = new TLongHashSet(); queue.add(pos); visited.add(pos); while (!queue.isEmpty()) { pos = queue.remove(); if (supported.contains(pos)) { // If we find a block already known to be supported, it supports all blocks visited in the // search. supported.addAll(visited); return true; } if (++this.visitsThisTick > MAX_SEARCH_VISITS_PER_TICK) { throw new MaxSearchVisitsExceeded(); } if (unsupported.contains(pos)) { // Don't continue the search through blocks known to be unsupported continue; } Block block = blockAt(world, pos); if (block == null) continue; boolean selfSupporting = true; for (FallingBlocksRule rule : this.rules) { if (rule.canFall(block)) { // If a rule matches, this block is not self-supporting, // and its status depends on the final result of the search. selfSupporting = false; // Continue the search through any neighbors that are capable of // supporting this block, and have not yet been visited. for (BlockFace face : NEIGHBORS) { long neighborPos = neighborPos(pos, face); if (!visited.contains(neighborPos)) { Block neighbor = blockAt(world, neighborPos); if (rule.canSupport(neighbor, face)) { queue.add(neighborPos); visited.add(neighborPos); } } } } } if (selfSupporting) { // If no rules match this block, then it is self-supporting, // and it can support all the other visited blocks. supported.addAll(visited); return true; } } // If the entire block network has been searched without finding a // supported block, then we know the entire network is unsupported. unsupported.addAll(visited); return false; }
Example 13
Source File: FallingBlocksMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
/** * Test if the given block is either self-supporting (doesn't match any falling rules) or is adjacent to a supported block. * The supported and unsupported arguments may contain the results of previous completed searches. The blocks visited by * this search will be added to one or the other set depending on the final result. * * @param pos position of the block to test * @param supported set of blocks already known to be supported * @param unsupported set of blocks already known to be unsupported * * @return true iff the given block is definitely supported */ private boolean isSupported(long pos, TLongSet supported, TLongSet unsupported) throws MaxSearchVisitsExceeded { World world = this.getMatch().getWorld(); LongDeque queue = new LongDeque(); TLongSet visited = new TLongHashSet(); queue.add(pos); visited.add(pos); while(!queue.isEmpty()) { pos = queue.remove(); if(supported.contains(pos)) { // If we find a block already known to be supported, it supports all blocks visited in the search. supported.addAll(visited); return true; } if(++this.visitsThisTick > MAX_SEARCH_VISITS_PER_TICK) { throw new MaxSearchVisitsExceeded(); } if(unsupported.contains(pos)) { // Don't continue the search through blocks known to be unsupported continue; } Block block = blockAt(world, pos); if(block == null) continue; boolean selfSupporting = true; for(FallingBlocksRule rule : this.rules) { if(rule.canFall(block)) { // If a rule matches, this block is not self-supporting, // and its status depends on the final result of the search. selfSupporting = false; // Continue the search through any neighbors that are capable of // supporting this block, and have not yet been visited. for(BlockFace face : NEIGHBORS) { long neighborPos = neighborPos(pos, face); if(!visited.contains(neighborPos)) { Block neighbor = blockAt(world, neighborPos); if(rule.canSupport(neighbor, face)) { queue.add(neighborPos); visited.add(neighborPos); } } } } } if(selfSupporting) { // If no rules match this block, then it is self-supporting, // and it can support all the other visited blocks. supported.addAll(visited); return true; } } // If the entire block network has been searched without finding a // supported block, then we know the entire network is unsupported. unsupported.addAll(visited); return false; }