in graphjet-core/src/main/java/com/twitter/graphjet/algorithms/counting/tweet/TweetMetadataRecommendationInfo.java [82:142]
public void addToTweetSocialProofs(
byte socialProofType,
SmallArrayBasedLongToDoubleMap userSocialProofs,
long rightNode,
int maxUserSocialProofSize,
int maxTweetSocialProofSize
) {
Map<Long, LongList> socialProofByType = socialProof.get(socialProofType);
// userSocialProofs.keys might contain legitimate duplicates. for example, a user replies a
// tweet multiple times.
long[] leftNodes = userSocialProofs.keys();
if (socialProofByType == null) {
// if this is the first social proof of this type, for each user social proof, create an empty
// tweetIds list, add tweet id in the list, and then add the list to socialProof along with
// the user id.
socialProofByType = new HashMap<Long, LongList>();
for (int i = 0; i < userSocialProofs.size(); i++) {
// update tweetIds if one of the following conditions is true.
// 1. userSocialProofs does not contain duplicates.
// 2. userSocialProofs has duplicates but this is the first time to add rightNode.
if (userSocialProofs.size() == userSocialProofs.uniqueKeysSize()
|| !socialProofByType.containsKey(leftNodes[i])) {
LongList tweetIds = new LongArrayList(INITIAL_TWEET_ARRAY_SIZE);
tweetIds.add(rightNode);
socialProofByType.put(leftNodes[i], tweetIds);
}
}
socialProof.put(socialProofType, socialProofByType);
} else {
// if the social proof type is already in the map, for each user social proof, create or
// update the corresponding tweet social proof.
for (int i = 0; i < userSocialProofs.size(); i++) {
LongList tweetIds = socialProofByType.get(leftNodes[i]);
// update tweetIds if one of the following conditions is true.
// 1. userSocialProofs does not contain duplicates.
// 2. userSocialProofs has duplicates but this is the first time to add rightNode.
if (userSocialProofs.size() == userSocialProofs.uniqueKeysSize()
|| (tweetIds == null || !tweetIds.contains(rightNode))) {
if (socialProofByType.size() < maxUserSocialProofSize) {
if (tweetIds == null) {
tweetIds = new LongArrayList(INITIAL_TWEET_ARRAY_SIZE);
socialProofByType.put(leftNodes[i], tweetIds);
}
if (tweetIds.size() < maxTweetSocialProofSize) {
tweetIds.add(rightNode);
}
} else {
if (tweetIds != null && tweetIds.size() < maxTweetSocialProofSize) {
tweetIds.add(rightNode);
}
}
}
}
}
}