it.unimi.dsi.fastutil.longs.LongList Java Examples

The following examples show how to use it.unimi.dsi.fastutil.longs.LongList. 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_v361.java    From Protocol with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, LevelChunkPacket packet) {
    VarInts.writeInt(buffer, packet.getChunkX());
    VarInts.writeInt(buffer, packet.getChunkZ());
    VarInts.writeUnsignedInt(buffer, packet.getSubChunksLength());
    buffer.writeBoolean(packet.isCachingEnabled());
    if (packet.isCachingEnabled()) {
        LongList blobIds = packet.getBlobIds();
        VarInts.writeUnsignedInt(buffer, blobIds.size());

        for (long blobId : blobIds) {
            buffer.writeLongLE(blobId);
        }
    }

    BedrockUtils.writeByteArray(buffer, packet.getData());
}
 
Example #2
Source File: KnowledgeBase.java    From fasten with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the successors of a given node by signature.
 *
 * This method is semantically equivalent to {@link #successors(Node)}, but it uses node signatures,
 * allowing for faster visits. It is just useful for statistics and debugging.
 *
 * @param node a node signature.
 * @return the set of signatures of successors.
 * @see #successors(Node)
 */
public LongList successors(final long nodeSig) {
	final long gid = gid(nodeSig);
	final long index = index(nodeSig);
	final CallGraph callGraph = callGraphs.get(index);
	assert callGraph != null;

	final CallGraphData callGraphData = callGraph.callGraphData();
	final LongList successors = callGraphData.successors(gid);

	final LongArrayList result = new LongArrayList();

	/* In the successor case, internal nodes can be added directly... */
	for (final long x : successors)
		if (callGraphData.isExternal(x))
			for (final LongIterator revisions = GIDAppearsIn.get(x).iterator(); revisions.hasNext();)
				result.add(signature(x, revisions.nextLong()));
		else result.add(signature(x, index));

	return result;
}
 
Example #3
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 #4
Source File: TopSecondDegreeByCountTweetMetadataRecsGenerator.java    From GraphJet with Apache License 2.0 6 votes vote down vote up
private static boolean isLessThanMinUserSocialProofSize(
  Map<Byte, Map<Long, LongList>> socialProofs,
  int minUserSocialProofSize
) {
  // the sum of tweet users and retweet users needs to be greater than a threshold
  byte[] metadataSocialProofTypes = {
    RecommendationRequest.RETWEET_SOCIAL_PROOF_TYPE,
    RecommendationRequest.AUTHOR_SOCIAL_PROOF_TYPE};
  long socialProofSizeSum = 0;

  for (byte socialProofType: metadataSocialProofTypes) {
    if (socialProofs.get(socialProofType) != null) {
      socialProofSizeSum += socialProofs.get(socialProofType).size();
    }
  }

  return socialProofSizeSum < minUserSocialProofSize;
}
 
Example #5
Source File: TopSecondDegreeByCountForMomentTest.java    From GraphJet with Apache License 2.0 6 votes vote down vote up
@Test
public void testTopSecondDegreeByCountForMomentWithSmallGraph3() throws Exception {
  // Test 3: Test limiting minimum number of minimum per social proof
  LongList metadata3 = new LongArrayList(new long[]{0, 0, 0});
  HashMap<Byte, ConnectingUsersWithMetadata> socialProofFor3 = new HashMap<> ();
  socialProofFor3.put((byte) 1, new ConnectingUsersWithMetadata(new LongArrayList(new long[]{1, 2, 3}), metadata3));

  Map<Byte, Integer> minUserPerSocialProof = new HashMap<>();
  List<TopSecondDegreeByCountRecommendationInfo> expectedTopResults = new ArrayList<>();

  byte[] socialProofTypes = new byte[] {0, 1, 2, 3};
  RecommendationStats expectedTopSecondDegreeByCountStats = new RecommendationStats(5, 6, 17, 2, 4, 0);

  int maxNumResults = 3;
  minUserPerSocialProof.put((byte) 1, 3); // 3 moments per proof
  expectedTopResults.clear();
  expectedTopResults.add(new MomentRecommendationInfo(3,3.0, socialProofFor3));
  testTopSecondDegreeByCountHelper(
    maxNumResults,
    minUserPerSocialProof,
    socialProofTypes,
    expectedTopResults,
    expectedTopSecondDegreeByCountStats);
}
 
Example #6
Source File: TopSecondDegreeByCountForUserTest.java    From GraphJet with Apache License 2.0 6 votes vote down vote up
@Test
public void testTopSecondDegreeByCountForUsersWithSmallGraph2() throws Exception {
  // Test 2: Test with small maxNumResults
  LongList metadata = new LongArrayList(new long[]{0, 0, 0});
  HashMap<Byte, ConnectingUsersWithMetadata> socialProofFor3 = new HashMap<> ();
  socialProofFor3.put((byte) 1, new ConnectingUsersWithMetadata(new LongArrayList(new long[]{1, 2, 3}), metadata));

  Map<Byte, Integer> minUserPerSocialProof = new HashMap<>();
  List<UserRecommendationInfo> expectedTopResults = new ArrayList<>();

  byte[] socialProofTypes = new byte[] {0, 1, 2, 3};
  RecommendationStats expectedTopSecondDegreeByCountStats = new RecommendationStats(5, 6, 17, 2, 4, 0);

  int maxNumResults = 1;
  expectedTopResults.clear();
  expectedTopResults.add(new UserRecommendationInfo(3, 3.0, socialProofFor3));
  testTopSecondDegreeByCountHelper(
    maxNumResults,
    minUserPerSocialProof,
    socialProofTypes,
    expectedTopResults,
    expectedTopSecondDegreeByCountStats);
}
 
Example #7
Source File: TopSecondDegreeByCountForUserTest.java    From GraphJet with Apache License 2.0 6 votes vote down vote up
@Test
public void testTopSecondDegreeByCountForUsersWithSmallGraph3() throws Exception {
  // Test 3: Test limiting minimum number of users per social proof
  LongList metadata = new LongArrayList(new long[]{0, 0, 0});
  HashMap<Byte, ConnectingUsersWithMetadata> socialProofFor3 = new HashMap<> ();
  socialProofFor3.put((byte) 1, new ConnectingUsersWithMetadata(new LongArrayList(new long[]{1, 2, 3}), metadata));

  Map<Byte, Integer> minUserPerSocialProof = new HashMap<>();
  List<UserRecommendationInfo> expectedTopResults = new ArrayList<>();

  byte[] socialProofTypes = new byte[] {0, 1, 2, 3};
  RecommendationStats expectedTopSecondDegreeByCountStats = new RecommendationStats(5, 6, 17, 2, 4, 0);

  int maxNumResults = 3;
  minUserPerSocialProof.put((byte) 1, 3); // 3 users per proof
  expectedTopResults.clear();
  expectedTopResults.add(new UserRecommendationInfo(3, 3.0, socialProofFor3));
  testTopSecondDegreeByCountHelper(
    maxNumResults,
    minUserPerSocialProof,
    socialProofTypes,
    expectedTopResults,
    expectedTopSecondDegreeByCountStats);
}
 
Example #8
Source File: TopSecondDegreeByCountForMomentTest.java    From GraphJet with Apache License 2.0 6 votes vote down vote up
@Test
public void testTopSecondDegreeByCountForMomentWithSmallGraph2() throws Exception {
  // Test 2: Test with small maxNumResults
  LongList metadata3 = new LongArrayList(new long[]{0, 0, 0});
  HashMap<Byte, ConnectingUsersWithMetadata> socialProofFor3 = new HashMap<> ();
  socialProofFor3.put((byte) 1, new ConnectingUsersWithMetadata(new LongArrayList(new long[]{1, 2, 3}), metadata3));

  Map<Byte, Integer> minUserPerSocialProof = new HashMap<>();
  List<TopSecondDegreeByCountRecommendationInfo> expectedTopResults = new ArrayList<>();

  byte[] socialProofTypes = new byte[] {0, 1, 2, 3};
  RecommendationStats expectedTopSecondDegreeByCountStats = new RecommendationStats(5, 6, 17, 2, 4, 0);

  int maxNumResults = 1;
  expectedTopResults.clear();
  expectedTopResults.add(new MomentRecommendationInfo(3,3.0, socialProofFor3));
  testTopSecondDegreeByCountHelper(
    maxNumResults,
    minUserPerSocialProof,
    socialProofTypes,
    expectedTopResults,
    expectedTopSecondDegreeByCountStats);
}
 
Example #9
Source File: SalsaBitmaskTest.java    From GraphJet with Apache License 2.0 6 votes vote down vote up
private StaticBipartiteGraph buildTestGraph() {
  Long2ObjectMap<LongList> leftSideGraph = new Long2ObjectOpenHashMap<LongList>(3);
  leftSideGraph.put(1, new LongArrayList(new long[]{2, 3, 4, 5}));
  leftSideGraph.put(2, new LongArrayList(new long[]{tweetNode, summaryNode, photoNode, playerNode,
      2, 3}));
  leftSideGraph.put(3, new LongArrayList(new long[]{tweetNode, summaryNode, photoNode, playerNode,
      promotionNode, 4, 5}));

  Long2ObjectMap<LongList> rightSideGraph = new Long2ObjectOpenHashMap<LongList>(10);
  rightSideGraph.put(2, new LongArrayList(new long[]{1, 2}));
  rightSideGraph.put(3, new LongArrayList(new long[]{1, 2}));
  rightSideGraph.put(4, new LongArrayList(new long[]{1, 3}));
  rightSideGraph.put(5, new LongArrayList(new long[]{1, 3}));
  rightSideGraph.put(tweetNode, new LongArrayList(new long[]{2, 3}));
  rightSideGraph.put(summaryNode, new LongArrayList(new long[]{2, 3}));
  rightSideGraph.put(photoNode, new LongArrayList(new long[]{2, 3}));
  rightSideGraph.put(playerNode, new LongArrayList(new long[]{2, 3}));
  rightSideGraph.put(promotionNode, new LongArrayList(new long[]{3}));

  return new StaticBipartiteGraph(leftSideGraph, rightSideGraph);

}
 
Example #10
Source File: BipartiteGraphTestHelper.java    From GraphJet with Apache License 2.0 6 votes vote down vote up
/**
 * Build a small test bipartite graph.
 *
 * @return a small test bipartite graph
 */
public static StaticBipartiteGraph buildSmallTestBipartiteGraph() {
  Long2ObjectMap<LongList> leftSideGraph = new Long2ObjectOpenHashMap<LongList>(3);
  leftSideGraph.put(1, new LongArrayList(new long[]{2, 3, 4, 5}));
  leftSideGraph.put(2, new LongArrayList(new long[]{5, 6, 10}));
  leftSideGraph.put(3, new LongArrayList(new long[]{7, 8, 5, 9, 2, 10, 11, 1}));

  Long2ObjectMap<LongList> rightSideGraph = new Long2ObjectOpenHashMap<LongList>(10);
  rightSideGraph.put(1, new LongArrayList(new long[]{3}));
  rightSideGraph.put(2, new LongArrayList(new long[]{1, 3}));
  rightSideGraph.put(3, new LongArrayList(new long[]{1}));
  rightSideGraph.put(4, new LongArrayList(new long[]{1}));
  rightSideGraph.put(5, new LongArrayList(new long[]{1, 2, 3}));
  rightSideGraph.put(6, new LongArrayList(new long[]{2}));
  rightSideGraph.put(7, new LongArrayList(new long[]{3}));
  rightSideGraph.put(8, new LongArrayList(new long[]{3}));
  rightSideGraph.put(9, new LongArrayList(new long[]{3}));
  rightSideGraph.put(10, new LongArrayList(new long[]{2, 3}));
  rightSideGraph.put(11, new LongArrayList(new long[]{3}));

  return new StaticBipartiteGraph(leftSideGraph, rightSideGraph);
}
 
Example #11
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 #12
Source File: LevelChunkSerializer_v388.java    From Protocol with Apache License 2.0 6 votes vote down vote up
@Override
public void serialize(ByteBuf buffer, LevelChunkPacket packet) {
    VarInts.writeInt(buffer, packet.getChunkX());
    VarInts.writeInt(buffer, packet.getChunkZ());
    VarInts.writeUnsignedInt(buffer, packet.getSubChunksLength());
    buffer.writeBoolean(packet.isCachingEnabled());
    if (packet.isCachingEnabled()) {
        LongList blobIds = packet.getBlobIds();
        VarInts.writeUnsignedInt(buffer, blobIds.size());

        for (long blobId : blobIds) {
            buffer.writeLongLE(blobId);
        }
    }

    BedrockUtils.writeByteArray(buffer, packet.getData());
}
 
Example #13
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 #14
Source File: TopSecondDegreeByCountForMomentTest.java    From GraphJet with Apache License 2.0 5 votes vote down vote up
@Test
public void testTopSecondDegreeByCountForMomentWithSmallGraph1() throws Exception {
  // Test 1: Test regular test case without max result limitations
  LongList metadata1 = new LongArrayList(new long[]{0});
  LongList metadata3 = new LongArrayList(new long[]{0, 0, 0});
  HashMap<Byte, ConnectingUsersWithMetadata> socialProofFor3 = new HashMap<> ();
  socialProofFor3.put((byte) 1, new ConnectingUsersWithMetadata(new LongArrayList(new long[]{1, 2, 3}), metadata3));

  HashMap<Byte, ConnectingUsersWithMetadata> socialProofFor5 = new HashMap<> ();
  socialProofFor5.put((byte) 0, new ConnectingUsersWithMetadata(new LongArrayList(new long[]{2}), metadata1));
  socialProofFor5.put((byte) 3, new ConnectingUsersWithMetadata(new LongArrayList(new long[]{1}), metadata1));

  HashMap<Byte, ConnectingUsersWithMetadata> socialProofFor7 = new HashMap<> ();
  socialProofFor7.put((byte) 0, new ConnectingUsersWithMetadata(new LongArrayList(new long[]{1}), metadata1));
  socialProofFor7.put((byte) 1, new ConnectingUsersWithMetadata(new LongArrayList(new long[]{2}), metadata1));

  Map<Byte, Integer> minUserPerSocialProof = new HashMap<>();
  List<TopSecondDegreeByCountRecommendationInfo> expectedTopResults = new ArrayList<>();

  byte[] socialProofTypes = new byte[] {0, 1, 2, 3};
  RecommendationStats expectedTopSecondDegreeByCountStats = new RecommendationStats(5, 6, 17, 2, 4, 0);

  int maxNumResults = 3;
  expectedTopResults.add(new MomentRecommendationInfo(3,3.0, socialProofFor3));
  expectedTopResults.add(new MomentRecommendationInfo(5,2.5, socialProofFor5));
  expectedTopResults.add(new MomentRecommendationInfo(7,2.5, socialProofFor7));
  testTopSecondDegreeByCountHelper(
    maxNumResults,
    minUserPerSocialProof,
    socialProofTypes,
    expectedTopResults,
    expectedTopSecondDegreeByCountStats);
}
 
Example #15
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 #16
Source File: TopSecondDegreeByCountForUserTest.java    From GraphJet with Apache License 2.0 5 votes vote down vote up
@Test
public void testTopSecondDegreeByCountForUsersWithSmallGraph4() throws Exception {
  // Test 4: Test only allowing social proof type 3
  LongList metadata = new LongArrayList(new long[]{0});
  HashMap<Byte, ConnectingUsersWithMetadata> socialProofFor5 = new HashMap<> ();
  socialProofFor5.put((byte) 3, new ConnectingUsersWithMetadata(new LongArrayList(new long[]{1}), metadata));

  Map<Byte, Integer> minUserPerSocialProof = new HashMap<>();
  List<UserRecommendationInfo> expectedTopResults = new ArrayList<>();

  byte[] socialProofTypes = new byte[] {0, 1, 2, 3};
  RecommendationStats expectedTopSecondDegreeByCountStats = new RecommendationStats(5, 6, 17, 2, 4, 0);

  int maxNumResults = 3;
  minUserPerSocialProof = new HashMap<>();
  socialProofTypes = new byte[] {3};

  expectedTopSecondDegreeByCountStats = new RecommendationStats(5, 1, 2, 2, 2, 0);

  expectedTopResults.clear();
  expectedTopResults.add(new UserRecommendationInfo(5, 1.5, socialProofFor5));
  testTopSecondDegreeByCountHelper(
    maxNumResults,
    minUserPerSocialProof,
    socialProofTypes,
    expectedTopResults,
    expectedTopSecondDegreeByCountStats);
}
 
Example #17
Source File: TopSecondDegreeByCountForUserTest.java    From GraphJet with Apache License 2.0 5 votes vote down vote up
@Test
public void testTopSecondDegreeByCountForUsersWithSmallGraph1() throws Exception {
  // Test 1: Test regular test case without max result limitations
  LongList metadata1 = new LongArrayList(new long[]{0});
  LongList metadata3 = new LongArrayList(new long[]{0, 0, 0});

  HashMap<Byte, ConnectingUsersWithMetadata> socialProofFor3 = new HashMap<> ();
  socialProofFor3.put((byte) 1, new ConnectingUsersWithMetadata(new LongArrayList(new long[]{1, 2, 3}), metadata3));

  HashMap<Byte, ConnectingUsersWithMetadata> socialProofFor5 = new HashMap<> ();
  socialProofFor5.put((byte) 0, new ConnectingUsersWithMetadata(new LongArrayList(new long[]{2}), metadata1));
  socialProofFor5.put((byte) 3, new ConnectingUsersWithMetadata(new LongArrayList(new long[]{1}), metadata1));

  HashMap<Byte, ConnectingUsersWithMetadata> socialProofFor7 = new HashMap<> ();
  socialProofFor7.put((byte) 0, new ConnectingUsersWithMetadata(new LongArrayList(new long[]{1}), metadata1));
  socialProofFor7.put((byte) 1, new ConnectingUsersWithMetadata(new LongArrayList(new long[]{2}), metadata1));

  Map<Byte, Integer> minUserPerSocialProof = new HashMap<>();
  List<UserRecommendationInfo> expectedTopResults = new ArrayList<>();

  byte[] socialProofTypes = new byte[] {0, 1, 2, 3};
  RecommendationStats expectedTopSecondDegreeByCountStats = new RecommendationStats(5, 6, 17, 2, 4, 0);

  int maxNumResults = 3;
  expectedTopResults.add(new UserRecommendationInfo(3, 3.0, socialProofFor3));
  expectedTopResults.add(new UserRecommendationInfo(5, 2.5, socialProofFor5));
  expectedTopResults.add(new UserRecommendationInfo(7, 2.5, socialProofFor7));
  testTopSecondDegreeByCountHelper(
    maxNumResults,
    minUserPerSocialProof,
    socialProofTypes,
    expectedTopResults,
    expectedTopSecondDegreeByCountStats);
}
 
Example #18
Source File: TweetMetadataRecommendationInfo.java    From GraphJet with Apache License 2.0 5 votes vote down vote up
/**
 * Specify the metadata recommendation, such as hashtag and url.
 */
public TweetMetadataRecommendationInfo(int recommendation, RecommendationType type, double weight,
                                       Map<Byte, Map<Long, LongList>> socialProof) {
  this.recommendation = recommendation;
  this.recommendationType = type;
  this.weight = weight;
  this.socialProof = socialProof;
}
 
Example #19
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 #20
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 #21
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 #22
Source File: KnowledgeBase.java    From fasten with Apache License 2.0 5 votes vote down vote up
@Override
public LongList predecessors(final long node) {
	final int lid = GID2LID.get(node);
	if (lid < 0) throw new IllegalArgumentException("GID " + node + " does not exist");
	final int indegree = transpose.outdegree(lid);
	final LongArrayList gidList = new LongArrayList(indegree);
	for (final int s: transpose.successorArray(lid)) gidList.add(LID2GID[s]);
	return gidList;
}
 
Example #23
Source File: BipartiteGraphTestHelper.java    From GraphJet with Apache License 2.0 5 votes vote down vote up
/**
 * Build a small test bipartite graph.
 *
 * @return a small test bipartite graph
 */
public static StaticLeftIndexedBipartiteGraph buildSmallTestLeftIndexedBipartiteGraph() {
  Long2ObjectMap<LongList> leftSideGraph = new Long2ObjectOpenHashMap<LongList>(3);
  leftSideGraph.put(1, new LongArrayList(new long[]{2, 3, 4, 5}));
  leftSideGraph.put(2, new LongArrayList(new long[]{5, 6, 10}));
  leftSideGraph.put(3, new LongArrayList(new long[]{7, 8, 5, 9, 2, 10, 11, 1}));

  return new StaticLeftIndexedBipartiteGraph(leftSideGraph);
}
 
Example #24
Source File: SemiExternalGammaListTest.java    From database with GNU General Public License v2.0 5 votes vote down vote up
public void testSemiExternalGammaListGammaCoding() throws IOException {

		long[] longs = { 10, 300, 450, 650, 1000, 1290, 1699 };
		LongList listLongs = new LongArrayList( longs );

		SemiExternalGammaList list = new SemiExternalGammaList( buildInputStream( listLongs ), 1, listLongs.size() );
		for ( int i = 0; i < longs.length; ++i ) {
			assertEquals( ( "test failed for index: " + i ), longs[ i ], list.getLong( i ) );
		}

		list = new SemiExternalGammaList( buildInputStream( listLongs ), 2, listLongs.size() );
		for ( int i = 0; i < longs.length; ++i ) {
			assertEquals( ( "test failed for index: " + i ), longs[ i ], list.getLong( i ) );
		}

		list = new SemiExternalGammaList( buildInputStream( listLongs ), 4, listLongs.size() );
		for ( int i = 0; i < longs.length; ++i ) {
			assertEquals( ( "test failed for index: " + i ), longs[ i ], list.getLong( i ) );
		}

		list = new SemiExternalGammaList( buildInputStream( listLongs ), 7, listLongs.size() );
		for ( int i = 0; i < longs.length; ++i ) {
			assertEquals( ( "test failed for index: " + i ), longs[ i ], list.getLong( i ) );
		}
		
		list = new SemiExternalGammaList( buildInputStream( listLongs ), 8, listLongs.size() );
		for ( int i = 0; i < longs.length; ++i ) {
			assertEquals( ( "test failed for index: " + i ), longs[ i ], list.getLong( i ) );
		}
    }
 
Example #25
Source File: SemiExternalGammaListTest.java    From database with GNU General Public License v2.0 5 votes vote down vote up
public void testEmptySemiExternalGammaListGammaCoding() throws IOException {

		long[] longs = {  };
		LongList listOffsets = new LongArrayList( longs );

		new SemiExternalGammaList( buildInputStream( listOffsets ), 1, listOffsets.size() );
		assertTrue( true );
    }
 
Example #26
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 #27
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 #28
Source File: FlamdexCompare.java    From imhotep with Apache License 2.0 5 votes vote down vote up
private static Map<String, LongSet> rewriteIntFields(Map<String, LongList> map) {
    Map<String, LongSet> ret = Maps.newHashMapWithExpectedSize(map.size());
    for (String key : map.keySet()) {
        ret.put(key, new LongOpenHashSet(map.get(key)));
    }
    return ret;
}
 
Example #29
Source File: TestColumnIndexFilter.java    From parquet-mr with Apache License 2.0 5 votes vote down vote up
private static void assertAllRows(RowRanges ranges, long rowCount) {
  LongList actualList = new LongArrayList();
  ranges.iterator().forEachRemaining((long value) -> actualList.add(value));
  LongList expectedList = new LongArrayList();
  LongStream.range(0, rowCount).forEach(expectedList::add);
  assertArrayEquals(expectedList + " != " + actualList, expectedList.toLongArray(), actualList.toLongArray());
}
 
Example #30
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();
  }
}