Java Code Examples for it.unimi.dsi.fastutil.longs.LongList#add()

The following examples show how to use it.unimi.dsi.fastutil.longs.LongList#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: LevelChunkSerializer_v388.java    From Protocol with Apache License 2.0 6 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, LevelChunkPacket packet) {
    packet.setChunkX(VarInts.readInt(buffer));
    packet.setChunkZ(VarInts.readInt(buffer));
    packet.setSubChunksLength(VarInts.readUnsignedInt(buffer));
    packet.setCachingEnabled(buffer.readBoolean());

    if (packet.isCachingEnabled()) {
        LongList blobIds = packet.getBlobIds();
        int length = VarInts.readUnsignedInt(buffer);

        for (int i = 0; i < length; i++) {
            blobIds.add(buffer.readLongLE());
        }
    }
    packet.setData(BedrockUtils.readByteArray(buffer));
}
 
Example 2
Source File: LevelChunkSerializer_v361.java    From Protocol with Apache License 2.0 6 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, LevelChunkPacket packet) {
    packet.setChunkX(VarInts.readInt(buffer));
    packet.setChunkZ(VarInts.readInt(buffer));
    packet.setSubChunksLength(VarInts.readUnsignedInt(buffer));
    packet.setCachingEnabled(buffer.readBoolean());

    if (packet.isCachingEnabled()) {
        LongList blobIds = packet.getBlobIds();
        int length = VarInts.readUnsignedInt(buffer);

        for (int i = 0; i < length; i++) {
            blobIds.add(buffer.readLongLE());
        }
    }
    packet.setData(BedrockUtils.readByteArray(buffer));
}
 
Example 3
Source File: BipartiteGraphTestHelper.java    From GraphJet with Apache License 2.0 6 votes vote down vote up
/**
 * Build a random 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 random     is the random number generator to use for constructing the graph
 * @return a random bipartite graph
 */
public static StaticBipartiteGraph buildRandomBipartiteGraph(
    int leftSize, int rightSize, double edgeProbability, Random random) {
  Long2ObjectMap<LongList> leftSideGraph = new Long2ObjectOpenHashMap<LongList>(leftSize);
  Long2ObjectMap<LongList> rightSideGraph = new Long2ObjectOpenHashMap<LongList>(rightSize);
  int averageLeftDegree = (int) (rightSize * edgeProbability);
  int averageRightDegree = (int) (leftSize * edgeProbability);
  for (int i = 0; i < leftSize; i++) {
    leftSideGraph.put(i, new LongArrayList(averageLeftDegree));
    for (int j = 0; j < rightSize; j++) {
      if (random.nextDouble() < edgeProbability) {
        leftSideGraph.get(i).add(j);
        if (rightSideGraph.containsKey(j)) {
          rightSideGraph.get(j).add(i);
        } else {
          LongList rightSideList = new LongArrayList(averageRightDegree);
          rightSideList.add(i);
          rightSideGraph.put(j, rightSideList);
        }
      }
    }
  }

  return new StaticBipartiteGraph(leftSideGraph, rightSideGraph);
}
 
Example 4
Source File: ClientCacheBlobStatusSerializer_v388.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, ClientCacheBlobStatusPacket packet) {
    int acksLength = VarInts.readUnsignedInt(buffer);
    int naksLength = VarInts.readUnsignedInt(buffer);

    LongList acks = packet.getAcks();
    for (int i = 0; i < acksLength; i++) {
        acks.add(buffer.readLongLE());
    }

    LongList naks = packet.getNaks();
    for (int i = 0; i < naksLength; i++) {
        naks.add(buffer.readLongLE());
    }
}
 
Example 5
Source File: ClientCacheBlobStatusSerializer_v361.java    From Protocol with Apache License 2.0 5 votes vote down vote up
@Override
public void deserialize(ByteBuf buffer, ClientCacheBlobStatusPacket packet) {
    int acksLength = VarInts.readUnsignedInt(buffer);
    int naksLength = VarInts.readUnsignedInt(buffer);

    LongList acks = packet.getAcks();
    for (int i = 0; i < acksLength; i++) {
        acks.add(buffer.readLongLE());
    }

    LongList naks = packet.getNaks();
    for (int i = 0; i < naksLength; i++) {
        naks.add(buffer.readLongLE());
    }
}
 
Example 6
Source File: BitSetUtil.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
public static LongList convertToLongList(BitSet set) {
    LongList bits = new LongArrayList();
    int lastIndex = set.nextSetBit(0);
    while (lastIndex != -1) {
        bits.add(lastIndex);
        lastIndex = set.nextSetBit(lastIndex + 1);
    }
    return bits;
}
 
Example 7
Source File: CombinedInclusionTester.java    From metanome-algorithms with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(List<List<long[]>> tableSamplesList) {
    // Collect all column combinations that can be inserted.
    List<SimpleColumnCombination> combinations = new ArrayList<>();
    for (Map<SimpleColumnCombination, AD> hllsByColumnCombo : adByTable.values()) {
        combinations.addAll(hllsByColumnCombo.keySet());
    }
    for (int i = 0; i < combinations.size(); i++) {
        combinations.get(i).setIndex(i);
    }
    sampledInvertedIndex.setMaxId(combinations.size() - 1);

    // Now create according hashes from the table samples and initialize the inverted index with them.
    LongList samples = new LongArrayList();
    for (int table = 0; table < tableSamplesList.size(); table++) {
        Map<SimpleColumnCombination, AD> adByColumnCombinations = adByTable.get(table);
        if (adByColumnCombinations != null) {
            List<long[]> tableSamples = tableSamplesList.get(table);
            for (long[] sampleRow : tableSamples) {
                for (Map.Entry<SimpleColumnCombination, AD> entry : adByColumnCombinations.entrySet()) {
                    SimpleColumnCombination combination = entry.getKey();
                    long combinedHash = 0;
                    int[] columns = combination.getColumns();
                    boolean anyNull = false;
                    for (int i = 0; i < columns.length; i++) {
                        long hash = sampleRow[columns[i]];
                        if (anyNull = hash == HashedColumnStore.NULLHASH) break;
                        combinedHash = Long.rotateLeft(combinedHash, 1) ^ hash;
                    }
                    if (!anyNull) {
                        samples.add(combinedHash);
                    }
                }

            }
        }
    }
    sampledInvertedIndex.initialize(samples);
}
 
Example 8
Source File: StaticLeftIndexedBipartiteGraph.java    From GraphJet with Apache License 2.0 5 votes vote down vote up
@Override
public EdgeIterator getRandomLeftNodeEdges(long leftNode, int numSamples, Random random) {
  LongList samples = new LongArrayList(numSamples);
  for (int i = 0; i < numSamples; i++) {
    LongList edges = leftSideGraph.get(leftNode);
    samples.add(edges.get(random.nextInt(edges.size())));
  }
  return new MockEdgeIterator(samples.iterator());
}
 
Example 9
Source File: StaticBipartiteGraph.java    From GraphJet with Apache License 2.0 5 votes vote down vote up
@Override
public EdgeIterator getRandomLeftNodeEdges(long leftNode, int numSamples, Random random) {
  LongList samples = new LongArrayList(numSamples);
  for (int i = 0; i < numSamples; i++) {
    LongList edges = leftSideGraph.get(leftNode);
    samples.add(edges.get(random.nextInt(edges.size())));
  }
  return new MockEdgeIterator(samples.iterator());
}
 
Example 10
Source File: StaticBipartiteGraph.java    From GraphJet with Apache License 2.0 5 votes vote down vote up
@Override
public EdgeIterator getRandomRightNodeEdges(long rightNode, int numSamples, Random random) {
  LongList samples = new LongArrayList(numSamples);
  for (int i = 0; i < numSamples; i++) {
    LongList edges = rightSideGraph.get(rightNode);
    samples.add(edges.get(random.nextInt(edges.size())));
  }
  return new MockEdgeIterator(samples.iterator());
}
 
Example 11
Source File: FlamdexDocument.java    From imhotep with Apache License 2.0 5 votes vote down vote up
public void addIntTerms(@Nonnull final String field, @Nonnull final long[] terms) {
    final LongList list = prepareIntField(field);
    Preconditions.checkNotNull(terms, "terms list cannot be null");
    for (long term : terms) {
        list.add(term);
    }
}
 
Example 12
Source File: FlamdexDocument.java    From imhotep with Apache License 2.0 5 votes vote down vote up
public void addIntTerms(@Nonnull final String field, @Nonnull final Iterable<Long> terms) {
    final LongList list = prepareIntField(field);
    Preconditions.checkNotNull(terms, "terms list cannot be null");
    for (Long term : terms) {
        Preconditions.checkNotNull(term, "null terms not allowed");
        list.add(term);
    }
}
 
Example 13
Source File: ValueInTransformFunction.java    From incubator-pinot with Apache License 2.0 5 votes vote down vote up
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();
  }
}