本文整理匯總了Java中com.google.common.collect.ConcurrentHashMultiset.count方法的典型用法代碼示例。如果您正苦於以下問題:Java ConcurrentHashMultiset.count方法的具體用法?Java ConcurrentHashMultiset.count怎麽用?Java ConcurrentHashMultiset.count使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.collect.ConcurrentHashMultiset
的用法示例。
在下文中一共展示了ConcurrentHashMultiset.count方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getArgmaxAlignment
import com.google.common.collect.ConcurrentHashMultiset; //導入方法依賴的package包/類
private int getArgmaxAlignment(int idx) {
if (idx >= aCounter.size())
return -1;
// Linear search:
ConcurrentHashMultiset<Integer> aCounts = aCounter.get(idx);
int maxK = -1;
int maxV = Integer.MIN_VALUE;
String maxKLex = null;
for (int k : aCounts.elementSet()) {
int v = aCounts.count(k);
if (v == maxV) {
// If there is a tie, take lexicographic order as defined in Moses:
String kLex = AlignmentTemplate.alignmentToString(aIndex.get(k));
if (maxKLex == null)
maxKLex = AlignmentTemplate.alignmentToString(aIndex.get(maxK));
if (kLex.compareTo(maxKLex) < 0) {
maxK = k;
maxV = v;
maxKLex = kLex;
}
} else if (v > maxV) {
maxK = k;
maxV = v;
maxKLex = null;
}
}
assert (maxK >= 0);
return maxK;
}
示例2: countTreeOccurences
import com.google.common.collect.ConcurrentHashMultiset; //導入方法依賴的package包/類
@Override
public int countTreeOccurences(final TreeNode<T> root) {
final ConcurrentHashMultiset<TreeNode<T>> productions = grammar
.get(root.getData());
if (productions == null) {
return 0;
}
return productions.count(root);
}
示例3: tryAdd
import com.google.common.collect.ConcurrentHashMultiset; //導入方法依賴的package包/類
/**
* Attempts to add a single instance of the given value to the given
* multiset without exceeding the specified maximum number of values. If
* the value cannot be added without exceeding the maximum, false is
* returned.
*
* @param <T>
* The type of values contained within the multiset.
*
* @param multiset
* The multiset to attempt to add a value to.
*
* @param value
* The value to attempt to add.
*
* @param max
* The maximum number of each distinct value that the given multiset
* should hold, or zero if no limit applies.
*
* @return
* true if the value was successfully added without exceeding the
* specified maximum, false if the value could not be added.
*/
private <T> boolean tryAdd(ConcurrentHashMultiset<T> multiset, T value, int max) {
// Repeatedly attempt to add a new value to the given multiset until we
// explicitly succeed or explicitly fail
while (true) {
// Get current number of values
int count = multiset.count(value);
// Bail out if the maximum has already been reached
if (count >= max && max != 0)
return false;
// Attempt to add one more value
if (multiset.setCount(value, count, count+1))
return true;
// Try again if unsuccessful
}
}