本文整理汇总了Java中it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap.addTo方法的典型用法代码示例。如果您正苦于以下问题:Java Int2IntOpenHashMap.addTo方法的具体用法?Java Int2IntOpenHashMap.addTo怎么用?Java Int2IntOpenHashMap.addTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap
的用法示例。
在下文中一共展示了Int2IntOpenHashMap.addTo方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testUpdateIntSparseToIntSparse
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; //导入方法依赖的package包/类
@Test
public void testUpdateIntSparseToIntSparse() throws Exception {
ServerSparseIntRow serverSparseIntRow = new ServerSparseIntRow(rowId, startCol, endCol);
ByteBuf buf = Unpooled.buffer(16);
buf.writeInt(0);
buf.writeInt(0);
buf.writeInt(1);
buf.writeInt(1);
buf.writeInt(2);
buf.writeInt(2);
rowUpdater.updateIntSparseToIntSparse(3, buf, serverSparseIntRow);
Int2IntOpenHashMap hashMap = new Int2IntOpenHashMap();
hashMap.addTo(0, 0);
hashMap.addTo(1, 1);
hashMap.addTo(2, 2);
assertEquals(serverSparseIntRow.getData(), hashMap);
}
示例2: getFasterIntersectionMap
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; //导入方法依赖的package包/类
private Int2IntMap getFasterIntersectionMap(int uidx) {
Int2IntOpenHashMap intersectionMap = new Int2IntOpenHashMap();
intersectionMap.defaultReturnValue(0);
IntIterator iidxs = data.getUidxIidxs(uidx);
while (iidxs.hasNext()) {
IntIterator vidxs = data.getIidxUidxs(iidxs.nextInt());
while (vidxs.hasNext()) {
intersectionMap.addTo(vidxs.nextInt(), 1);
}
}
intersectionMap.remove(uidx);
return intersectionMap;
}
示例3: addCounts
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; //导入方法依赖的package包/类
private void addCounts(Int2IntOpenHashMap phraseToClusterMap, Int2IntOpenHashMap phraseContextCounts, Map<Integer, Int2IntOpenHashMap> prevClusterCounts, Map<Integer, Int2IntOpenHashMap> nextClusterCounts, int phrase, boolean includeIdentityCounts, int newCluster) {
Int2IntOpenHashMap phrasePrevClusterCounts = prevClusterCounts.get(newCluster);
if (phrasePrevClusterCounts == null) {
phrasePrevClusterCounts = ContextCountsUtils.createNewInt2IntMap();
prevClusterCounts.put(newCluster, phrasePrevClusterCounts);
}
for (Int2IntOpenHashMap.Entry otherPhraseEntry : phraseContextCounts.int2IntEntrySet()) {
int otherPhrase = otherPhraseEntry.getIntKey();
if (phrase != otherPhrase || includeIdentityCounts) {
int clusterOtherPhrase = otherPhrase == phrase ? newCluster : phraseToClusterMap.get(otherPhrase);
phrasePrevClusterCounts.addTo(clusterOtherPhrase, otherPhraseEntry.getIntValue());
Int2IntOpenHashMap otherPhraseNextCounts = nextClusterCounts.get(clusterOtherPhrase);
if (otherPhraseNextCounts == null) {
otherPhraseNextCounts = ContextCountsUtils.createNewInt2IntMap();
nextClusterCounts.put(clusterOtherPhrase, otherPhraseNextCounts);
}
otherPhraseNextCounts.addTo(newCluster, otherPhraseEntry.getValue());
}
}
}
示例4: mergeCounts
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; //导入方法依赖的package包/类
protected void mergeCounts(int smallCluster, int largeCluster, Map<Integer, Int2IntOpenHashMap> counts) {
//step 1: merge counts from small cluster to large cluster
Int2IntOpenHashMap countsSmallCluster = counts.remove(smallCluster);
Int2IntOpenHashMap countsLargeCluster = counts.get(largeCluster);
if (countsLargeCluster == null) {
countsLargeCluster = ContextCountsUtils.createNewInt2IntMap();
counts.put(largeCluster, countsLargeCluster);
}
for (Int2IntOpenHashMap.Entry entry : countsSmallCluster.int2IntEntrySet()) {
countsLargeCluster.addTo(entry.getIntKey(), entry.getIntValue());
}
//step 2: update all occurrences of small cluster to the large cluster
counts.values().parallelStream().forEach(countsForSingleCluster -> {
int prevCountsSmallCluster = countsForSingleCluster.remove(smallCluster);
if (prevCountsSmallCluster > 0) {
countsForSingleCluster.addTo(largeCluster, prevCountsSmallCluster);
}
});
}
示例5: mapCluster
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; //导入方法依赖的package包/类
private void mapCluster(Map<Integer, Int2IntOpenHashMap> counts, int oldCluster, int newCluster) {
Int2IntOpenHashMap mapOldCluster = counts.remove(oldCluster);
if (mapOldCluster != null) {
Int2IntOpenHashMap mapNewCluster = counts.get(newCluster);
if (mapNewCluster == null) {
counts.put(newCluster, mapOldCluster);
} else {
//merge maps
for (Map.Entry<Integer, Integer> entry : mapOldCluster.entrySet()) {
mapNewCluster.add(entry.getKey(), entry.getValue());
}
}
}
for (Int2IntOpenHashMap currMap : counts.values()) {
currMap.addTo(newCluster, currMap.remove(oldCluster));
}
}
示例6: testUpdateIntDenseToIntSparse
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; //导入方法依赖的package包/类
@Test
public void testUpdateIntDenseToIntSparse() throws Exception {
ServerSparseIntRow serverSparseIntRow = new ServerSparseIntRow(rowId, startCol, endCol);
ByteBuf buf = Unpooled.buffer(16);
buf.writeInt(0);
buf.writeInt(1);
buf.writeInt(2);
rowUpdater.updateIntDenseToIntSparse(3, buf, serverSparseIntRow);
Int2IntOpenHashMap hashMap = new Int2IntOpenHashMap();
hashMap.addTo(0, 0);
hashMap.addTo(1, 1);
hashMap.addTo(2, 2);
assertEquals(serverSparseIntRow.getData(), hashMap);
}
示例7: addCounts
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; //导入方法依赖的package包/类
private int addCounts(Map<Integer, Int2IntOpenHashMap> counts, Map<Integer, Int2IntOpenHashMap> countsToAdd, Int2IntOpenHashMap totals, int sign) {
int total = 0;
for (Map.Entry<Integer, Int2IntOpenHashMap> entry : countsToAdd.entrySet()) {
Int2IntOpenHashMap countsForKey = counts.get(entry.getKey());
if (countsForKey == null) {
countsForKey = ContextCountsUtils.createNewInt2IntMap();
counts.put(entry.getKey(), countsForKey);
}
int added = addCountsSingleMap(countsForKey, entry.getValue(), sign);
totals.addTo(entry.getKey(), added * sign);
total += added;
}
return total;
}
示例8: addCount
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; //导入方法依赖的package包/类
private void addCount(Int2IntOpenHashMap currentCounts, int key, int value) {
if (value != 0) {
int oldValue = currentCounts.addTo(key, value);
if (oldValue + value < 0) {
throw new RuntimeException("Negative count!");
}
}
}
示例9: replace
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; //导入方法依赖的package包/类
private Int2IntOpenHashMap replace(Int2IntOpenHashMap result, int smallCluster, int largeCluster) {
int countsSmallCluster = result.get(smallCluster);
if (countsSmallCluster > 0) {
result = result.clone();
result.remove(smallCluster);
result.addTo(largeCluster, countsSmallCluster);
}
return result;
}
示例10: merge
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; //导入方法依赖的package包/类
private Int2IntOpenHashMap merge(Int2IntOpenHashMap counts1, Int2IntOpenHashMap counts2) {
Int2IntOpenHashMap large = counts1.size() > counts2.size() ? counts1 : counts2;
Int2IntOpenHashMap small = counts1.size() > counts2.size() ? counts2 : counts1;
Int2IntOpenHashMap result = large.clone();
for (Int2IntOpenHashMap.Entry entry : small.int2IntEntrySet()) {
result.addTo(entry.getIntKey(), entry.getIntValue());
}
return result;
}
示例11: swapCounts
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; //导入方法依赖的package包/类
private Int2IntOpenHashMap swapCounts(Int2IntOpenHashMap origCounts, Int2IntOpenHashMap countsToSwap) {
if (countsToSwap != null) {
if (countsToSwap.size() > 1) {
throw new RuntimeException("Unexpected counts!");
}
int countToSwap = countsToSwap.get(DUMMY_CLUSTER);
if (countToSwap > 0) {
origCounts = origCounts.clone();
origCounts.addTo(DUMMY_CLUSTER, countToSwap);
reduceValue(origCounts, currClusterOfPhrase, countToSwap);
}
}
return origCounts;
}
示例12: addCounts
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; //导入方法依赖的package包/类
private static void addCounts(Int2IntOpenHashMap phraseToClusterMap, Map<Integer, Int2IntOpenHashMap> clusterCounts, Integer cluster, Int2IntOpenHashMap phraseCounts) {
Int2IntOpenHashMap clusterCountsForCluster = clusterCounts.get(cluster);
if (clusterCountsForCluster == null) {
clusterCountsForCluster = ContextCountsUtils.createNewInt2IntMap();
clusterCounts.put(cluster, clusterCountsForCluster);
}
for (Map.Entry<Integer, Integer> entry : phraseCounts.entrySet()) {
Integer cluster2 = phraseToClusterMap.get(entry.getKey());
clusterCountsForCluster.addTo(cluster2, entry.getValue());
}
}
示例13: reduceValue
import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; //导入方法依赖的package包/类
private void reduceValue(Int2IntOpenHashMap origCounts, int key, int countToReduce) {
int oldValue = origCounts.addTo(key, -countToReduce);
if (oldValue < countToReduce) {
throw new RuntimeException("Unexpected count " + oldValue);
}
}