gnu.trove.iterator.TLongIterator Java Examples

The following examples show how to use gnu.trove.iterator.TLongIterator. 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: TLongMultiIterator.java    From tinkergraph-gremlin with Apache License 2.0 6 votes vote down vote up
@Override
public long next() {
  if (iterators.isEmpty()) throw FastNoSuchElementException.instance();

  TLongIterator currentIterator = iterators.get(this.current);
  while (true) {
    if (currentIterator.hasNext()) {
      return currentIterator.next();
    } else {
      this.current++;
      if (this.current >= iterators.size())
        break;
      currentIterator = iterators.get(current);
    }
  }
  throw FastNoSuchElementException.instance();
}
 
Example #2
Source File: TLongMultiIterator.java    From tinkergraph-gremlin with Apache License 2.0 6 votes vote down vote up
@Override
public boolean hasNext() {
  if (this.current >= iterators.size())
    return false;

  TLongIterator currentIterator = iterators.get(this.current);

  while (true) {
    if (currentIterator.hasNext()) {
      return true;
    } else {
      this.current++;
      if (this.current >= iterators.size())
        break;
      currentIterator = iterators.get(this.current);
    }
  }
  return false;
}
 
Example #3
Source File: Sets.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
public static final TLongHashSet containedInFirstButNotInSecond(
		final TLongHashSet first,
		final TLongHashSet second)
{
	final TLongHashSet notInSecond = new TLongHashSet();
	for (final TLongIterator fIt = first.iterator(); fIt.hasNext(); )
	{
		final long p = fIt.next();
		if (!second.contains(p))
		{
			notInSecond.add(p);
		}
	}
	LOG.debug("First:         {}", first);
	LOG.debug("Second:        {}", second);
	LOG.debug("Not in second: {}", notInSecond);
	return notInSecond;
}
 
Example #4
Source File: BlockVectorSet.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public Iterator<BlockVector> iterator() {
    final TLongIterator iter = this.set.iterator();

    return new Iterator<BlockVector>() {
        @Override
        public boolean hasNext() {
            return iter.hasNext();
        }

        @Override
        public BlockVector next() {
            return decodePos(iter.next());
        }

        @Override
        public void remove() {
            iter.remove();
        }
    };
}
 
Example #5
Source File: BlockVectorSet.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Return an iterator that reuses a single BlockVector instance,
 * mutating it for each iteration.
 */
public Iterator<BlockVector> mutableIterator() {
    final TLongIterator iter = set.iterator();
    return new Iterator<BlockVector>() {
        final BlockVector value = new BlockVector();

        @Override
        public boolean hasNext() {
            return iter.hasNext();
        }

        @Override
        public BlockVector next() {
            return decodePos(iter.next(), value);
        }
    };
}
 
Example #6
Source File: BlockVectorSet.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public Iterator<BlockVector> iterator() {
  final TLongIterator iter = this.set.iterator();

  return new Iterator<BlockVector>() {
    @Override
    public boolean hasNext() {
      return iter.hasNext();
    }

    @Override
    public BlockVector next() {
      return BlockVectors.decodePos(iter.next());
    }

    @Override
    public void remove() {
      iter.remove();
    }
  };
}
 
Example #7
Source File: ToXdrTables.java    From monsoon with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private static TLongIntMap buildTimestampLookupTable(TLongList timestamps) {
    final TLongIntMap lookupTable = new TLongIntHashMap(timestamps.size(), 4, -1, -1);

    final TLongIterator iter = timestamps.iterator();
    for (int idx = 0; iter.hasNext(); ++idx)
        lookupTable.put(iter.next(), idx);

    return lookupTable;
}
 
Example #8
Source File: TLongHashSetSerializer.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void write(Kryo kryo, Output output, TLongHashSet object) {
	output.writeInt(object.size(), true);
	TLongIterator it = object.iterator();
	while (it.hasNext()) {
		kryo.writeObject(output, it.next());
	}
}
 
Example #9
Source File: GuildSetupNode.java    From JDA with Apache License 2.0 5 votes vote down vote up
private void completeSetup()
{
    updateStatus(GuildSetupController.Status.BUILDING);
    JDAImpl api = getController().getJDA();
    for (TLongIterator it = removedMembers.iterator(); it.hasNext(); )
        members.remove(it.next());
    removedMembers.clear();
    GuildImpl guild = api.getEntityBuilder().createGuild(id, partialGuild, members, expectedMemberCount);
    updateAudioManagerReference(guild);
    switch (type)
    {
    case AVAILABLE:
        api.handleEvent(new GuildAvailableEvent(api, api.getResponseTotal(), guild));
        getController().remove(id);
        break;
    case JOIN:
        api.handleEvent(new GuildJoinEvent(api, api.getResponseTotal(), guild));
        if (requestedChunk)
            getController().ready(id);
        else
            getController().remove(id);
        break;
    default:
        api.handleEvent(new GuildReadyEvent(api, api.getResponseTotal(), guild));
        getController().ready(id);
        break;
    }
    updateStatus(GuildSetupController.Status.READY);
    GuildSetupController.log.debug("Finished setup for guild {} firing cached events {}", id, cachedEvents.size());
    api.getClient().handle(cachedEvents);
    api.getEventCache().playbackCache(EventCache.Type.GUILD, id);
}
 
Example #10
Source File: Serializer.java    From tinkergraph-gremlin with Apache License 2.0 5 votes vote down vote up
/**
 * format: two `Map<Label, Array<EdgeId>>`, i.e. one Map for `IN` and one for `OUT` edges
 */
private void packEdgeIds(final MessageBufferPacker packer,
                         final Map<String, TLongSet> edgeIdsByLabel) throws IOException {
  packer.packMapHeader(edgeIdsByLabel.size());
  for (Map.Entry<String, TLongSet> entry : edgeIdsByLabel.entrySet()) {
    final String label = entry.getKey();
    packer.packString(label);
    final TLongSet edgeIds = entry.getValue();
    packer.packArrayHeader(edgeIds.size());
    final TLongIterator edgeIdIter = edgeIds.iterator();
    while (edgeIdIter.hasNext()) {
      packer.packLong(edgeIdIter.next());
    }
  }
}
 
Example #11
Source File: BlockVectorSet.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
public BlockVector chooseRandom(Random random) {
    // The Trove set uses a sparse array, so there isn't really any
    // faster way to do this, not even by messing with Trove internals.
    final TLongIterator iterator = set.iterator();
    long encoded = 0;
    for(int n = random.nextInt(size()); n >= 0; n--) {
        encoded = iterator.next();
    }
    return decodePos(encoded);
}
 
Example #12
Source File: SegmentMaskGenerators.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void convert(final LabelMultisetType input, final B output)
{
	final Set<Entry<Label>> inputSet        = input.entrySet();
	final int               validLabelsSize = validLabels.size();
	final int               inputSize       = inputSet.size();
	// no primitive type support for slf4j
	// http://mailman.qos.ch/pipermail/slf4j-dev/2005-August/000241.html
	if (LOG.isTraceEnabled())
	{
		LOG.trace("input size={}, validLabels size={}", inputSize, validLabelsSize);
	}
	long validLabelsContainedCount = 0;
	if (validLabelsSize < inputSize)
	{
		for (final TLongIterator it = validLabels.iterator(); it.hasNext(); ) {
			validLabelsContainedCount += input.count(it.next());
			if (validLabelsContainedCount >= minNumRequiredPixels) {
				output.set(true);
				return;
			}
		}
	}
	else
	{
		for (final Entry<Label> labelEntry : inputSet) {
			if (validLabels.contains(labelEntry.getElement().id())) {
				validLabelsContainedCount += labelEntry.getCount();
				if (validLabelsContainedCount >= minNumRequiredPixels) {
					output.set(true);
					return;
				}
			}
		}
	}
	output.set(false);
}
 
Example #13
Source File: SegmentMaskGenerators.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void convert(final LabelMultisetType input, final B output)
{
	final Set<Entry<Label>> inputSet        = input.entrySet();
	final int               validLabelsSize = validLabels.size();
	final int               inputSize       = inputSet.size();
	// no primitive type support for slf4j
	// http://mailman.qos.ch/pipermail/slf4j-dev/2005-August/000241.html
	if (LOG.isTraceEnabled())
	{
		LOG.trace("input size={}, validLabels size={}", inputSize, validLabelsSize);
	}

	if (validLabelsSize < inputSize)
	{
		for (final TLongIterator it = validLabels.iterator(); it.hasNext(); )
		{
			if (input.contains(it.next()))
			{
				output.set(true);
				return;
			}
		}
	}
	else
	{
		for (final Entry<Label> labelEntry : inputSet) {
			if (validLabels.contains(labelEntry.getElement().id())) {
				output.set(true);
				return;
			}
		}
	}
	output.set(false);
}
 
Example #14
Source File: MaskedSource.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Downsample affected blocks of img.
 * @param source
 * @param img
 * @param affectedBlocks
 * @param steps
 * @param interval
 */
public static void downsampleBlocks(
		final RandomAccessible<UnsignedLongType> source,
		final CachedCellImg<UnsignedLongType, LongAccess> img,
		final TLongSet affectedBlocks,
		final int[] steps,
		final Interval interval)
{
	final BlockSpec blockSpec = new BlockSpec(img.getCellGrid());

	final long[] intersectedCellMin = new long[blockSpec.grid.numDimensions()];
	final long[] intersectedCellMax = new long[blockSpec.grid.numDimensions()];

	LOG.debug("Initializing affected blocks: {}", affectedBlocks);
	for (final TLongIterator it = affectedBlocks.iterator(); it.hasNext(); )
	{
		final long blockId = it.next();
		blockSpec.fromLinearIndex(blockId);

		Arrays.setAll(intersectedCellMin, d -> blockSpec.min[d]);
		Arrays.setAll(intersectedCellMax, d -> blockSpec.max[d]);

		intersect(intersectedCellMin, intersectedCellMax, interval);

		if (isNonEmpty(intersectedCellMin, intersectedCellMax))
		{
			LOG.trace("Downsampling for intersected min/max: {} {}", intersectedCellMin, intersectedCellMax);
			downsample(source, Views.interval(img, intersectedCellMin, intersectedCellMax), steps);
		}
	}
}
 
Example #15
Source File: CachedGridEntry.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Collection<IBlockState> getGeneratedBlocks(OreDepositDefinition definition, int chunkX, int chunkZ) {
    long chunkId = (long) chunkX << 32 | chunkZ & 0xFFFFFFFFL;
    ChunkDataEntry chunkDataEntry = dataByChunkPos.get(chunkId);
    if (chunkDataEntry != null) {
        TLongSet longSet = chunkDataEntry.generatedBlocksSet.get(definition);
        ArrayList<IBlockState> blockStates = new ArrayList<>();
        TLongIterator iterator = longSet.iterator();
        while (iterator.hasNext())
            blockStates.add(Block.getStateById((int) iterator.next()));
        return blockStates;
    }
    return Collections.emptyList();
}
 
Example #16
Source File: GuildSetupController.java    From JDA with Apache License 2.0 5 votes vote down vote up
private void tryChunking()
{
    if (api.useIntents())
    {
        // can only send a single guild id for this
        chunkingGuilds.forEach((id) -> {
            sendChunkRequest(id);
            return true;
        });
        chunkingGuilds.clear();
        return;
    }

    if (chunkingGuilds.size() >= 50)
    {
        // request chunks
        final DataArray subset = DataArray.empty();
        for (final TLongIterator it = chunkingGuilds.iterator(); subset.length() < 50; )
        {
            subset.add(it.next());
            it.remove();
        }
        sendChunkRequest(subset);
    }
    if (incompleteCount > 0 && chunkingGuilds.size() >= incompleteCount)
    {
        // request last chunks
        final DataArray array = DataArray.empty();
        chunkingGuilds.forEach((guild) -> {
            array.add(guild);
            return true;
        });
        chunkingGuilds.clear();
        sendChunkRequest(array);
    }
}
 
Example #17
Source File: LongDeque.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public void addAll(TLongCollection values) {
    ensureCapacity(values.size());
    for(TLongIterator iter = values.iterator(); iter.hasNext();) {
        addUnchecked(iter.next());
    }
}
 
Example #18
Source File: TmpFileBasedColumnMajorTSData.java    From monsoon with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public Iterator<TimestampedMetric> iterator(TLongList timestamps) {
    final TLongIterator timestampIter = timestamps.iterator();
    return Iterators.transform(
            iterator(),
            metric -> new TimestampedMetric(new DateTime(timestampIter.next(), DateTimeZone.UTC), metric));
}
 
Example #19
Source File: TLongMultiIterator.java    From tinkergraph-gremlin with Apache License 2.0 4 votes vote down vote up
public TLongMultiIterator(List<TLongIterator> iterators) {
  this.iterators = iterators;
}
 
Example #20
Source File: LongDeque.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
public void addAll(TLongCollection values) {
  ensureCapacity(values.size());
  for (TLongIterator iter = values.iterator(); iter.hasNext(); ) {
    addUnchecked(iter.next());
  }
}