本文整理汇总了Java中java.util.BitSet.cardinality方法的典型用法代码示例。如果您正苦于以下问题:Java BitSet.cardinality方法的具体用法?Java BitSet.cardinality怎么用?Java BitSet.cardinality使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.BitSet
的用法示例。
在下文中一共展示了BitSet.cardinality方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: from
import java.util.BitSet; //导入方法依赖的package包/类
static CharMatcher from(BitSet chars, String description) {
// Compute the filter.
long filter = 0;
int size = chars.cardinality();
boolean containsZero = chars.get(0);
// Compute the hash table.
char[] table = new char[chooseTableSize(size)];
int mask = table.length - 1;
for (int c = chars.nextSetBit(0); c != -1; c = chars.nextSetBit(c + 1)) {
// Compute the filter at the same time.
filter |= 1L << c;
int index = smear(c) & mask;
while (true) {
// Check for empty.
if (table[index] == 0) {
table[index] = (char) c;
break;
}
// Linear probing.
index = (index + 1) & mask;
}
}
return new SmallCharMatcher(table, filter, containsZero, description);
}
示例2: main
import java.util.BitSet; //导入方法依赖的package包/类
public static void main(String[] args) {
String[] malformedIPv4s = {"192.168.1.220..."};
BitSet expectedExceptions = new BitSet(malformedIPv4s.length);
expectedExceptions.clear();
for (int i = 0; i < malformedIPv4s.length; i++) {
try {
InetAddress.getAllByName(malformedIPv4s[i]);
} catch (UnknownHostException e) {
expectedExceptions.set(i);
}
}
for (int i = 0; i < malformedIPv4s.length; i++) {
if (!expectedExceptions.get(i)) {
System.out.println("getAllByName(\"" + malformedIPv4s[i] + "\") should throw exception.");
}
}
if (expectedExceptions.cardinality() != malformedIPv4s.length) {
throw new RuntimeException("Failed: some expected UnknownHostExceptions are not thrown.");
}
}
示例3: NullComparator
import java.util.BitSet; //导入方法依赖的package包/类
public NullComparator(BitSet mask, int count) {
super();
this.bigs = mask.toLongArray();
if(mask.cardinality() == 0){
mode = Mode.NONE;
four = 0;
eight = 0;
}else{
if(count > 64){
mode = Mode.BIG;
four = 0;
eight = 0;
}else if(count > 32){
mode = Mode.EIGHT;
four = 0;
eight = bigs[0];
} else {
mode = Mode.FOUR;
four = (int) bigs[0];
eight = 0;
}
}
}
示例4: subset
import java.util.BitSet; //导入方法依赖的package包/类
/**
* Returns a new instance, which contains a subset of the elements
* specified by the given BitSet. Indexes in the BitSet with a zero
* are included, while indexes with a one are excluded. Mutability
* of the result is inherited from the original.
*
* @param exclusionSet {@code non-null;} set of registers to exclude
* @return {@code non-null;} an appropriately-constructed instance
*/
public RegisterSpecList subset(BitSet exclusionSet) {
int newSize = size() - exclusionSet.cardinality();
if (newSize == 0) {
return EMPTY;
}
RegisterSpecList result = new RegisterSpecList(newSize);
int newIndex = 0;
for (int oldIndex = 0; oldIndex < size(); oldIndex++) {
if (!exclusionSet.get(oldIndex)) {
result.set0(newIndex, get0(oldIndex));
newIndex++;
}
}
if (isImmutable()) {
result.setImmutable();
}
return result;
}
示例5: bitSetToIntArray
import java.util.BitSet; //导入方法依赖的package包/类
private int[] bitSetToIntArray(BitSet live) {
int[] vars = new int[live.cardinality()];
int cnt = 0;
for (int i = live.nextSetBit(0); i >= 0; i = live.nextSetBit(i + 1), cnt++) {
vars[cnt] = i;
}
return vars;
}
示例6: onSuccess
import java.util.BitSet; //导入方法依赖的package包/类
@Override
public void onSuccess(@Nullable BitSet result) {
if (!failed.get()) {
long rowCount = result == null ? 0 : result.cardinality();
rowReceiver.setNextRow(new Row1(rowCount));
rowReceiver.finish();
}
}
示例7: solve2
import java.util.BitSet; //导入方法依赖的package包/类
static int solve2(char[][] board, int kDifferent) {
int height = board.length;
int width = board[0].length;
int result = 0;
BitSet[] aggregatedRows = new BitSet[width];
for (int yMin = 0; yMin < height; yMin++) {
for (int x = 0; x < width; x++) {
aggregatedRows[x] = new BitSet();
}
for (int yMax = yMin; yMax < height; yMax++) {
for (int x = 0; x < width; x++) {
aggregatedRows[x].set(board[yMax][x] - 'A');
}
for (int xMin = 0; xMin < width; xMin++) {
BitSet chars = new BitSet();
for (int xMax = xMin; xMax < width; xMax++) {
chars.or(aggregatedRows[xMax]);
if (chars.cardinality() == kDifferent) {
result++;
}
}
}
}
}
return result;
}
示例8: setUp
import java.util.BitSet; //导入方法依赖的package包/类
@BeforeExperiment void setUp() {
this.matcher = precomputed ? config.matcher.precomputed() : config.matcher;
if (size == Size.SMALL) {
BitSet tmp = new BitSet();
matcher.setBits(tmp);
int matchedCharCount = tmp.cardinality();
this.matcher = SmallCharMatcher.from(tmp, "");
}
this.string = checkString(length, percent, config.matchingChars,
new Random(), forceSlow, web);
}
示例9: updateEntrySet
import java.util.BitSet; //导入方法依赖的package包/类
private boolean updateEntrySet(BitSet entrySet, BitSet exitSet,
BitSet useBeforeDef, BitSet notDef) {
int card = entrySet.cardinality();
entrySet.or(exitSet);
entrySet.and(notDef);
entrySet.or(useBeforeDef);
return entrySet.cardinality() != card;
}
示例10: calcDomFronts
import java.util.BitSet; //导入方法依赖的package包/类
/**
* Calculates the dominance-frontier set.
* from "A Simple, Fast Dominance Algorithm" by Cooper,
* Harvey, and Kennedy; transliterated to Java.
*/
private void calcDomFronts() {
int szNodes = nodes.size();
for (int b = 0; b < szNodes; b++) {
SsaBasicBlock nb = nodes.get(b);
DomInfo nbInfo = domInfos[b];
BitSet pred = nb.getPredecessors();
if (pred.cardinality() > 1) {
for (int i = pred.nextSetBit(0); i >= 0;
i = pred.nextSetBit(i + 1)) {
for (int runnerIndex = i;
runnerIndex != nbInfo.idom; /* empty */) {
/*
* We can stop if we hit a block we already
* added label to, since we must be at a part
* of the dom tree we have seen before.
*/
if (runnerIndex == -1) break;
DomInfo runnerInfo = domInfos[runnerIndex];
if (runnerInfo.dominanceFrontiers.has(b)) {
break;
}
// Add b to runner's dominance frontier set.
runnerInfo.dominanceFrontiers.add(b);
runnerIndex = runnerInfo.idom;
}
}
}
}
}
示例11: MethodInvocation
import java.util.BitSet; //导入方法依赖的package包/类
public MethodInvocation(InlineInfo info, double probability, double relevance, BitSet freshlyInstantiatedArguments) {
this.callee = info;
this.probability = probability;
this.relevance = relevance;
this.freshlyInstantiatedArguments = freshlyInstantiatedArguments;
this.sizeFreshArgs = freshlyInstantiatedArguments == null ? 0 : freshlyInstantiatedArguments.cardinality();
}
示例12: allMatchingChars
import java.util.BitSet; //导入方法依赖的package包/类
private static String allMatchingChars(BitSet bitSet) {
final char[] result = new char[bitSet.cardinality()];
for (int j = 0, c = bitSet.nextSetBit(0); j < result.length; ++j) {
result[j] = (char) c;
c = bitSet.nextSetBit(c + 1);
}
return new String(result);
}
示例13: postDominanceFrontierAnalysis
import java.util.BitSet; //导入方法依赖的package包/类
/**
* Performs the post dominance frontier analysis.
*/
private void postDominanceFrontierAnalysis() {
BitSet out = new BitSet(edges.size());
for (Edge e : edges) {
// An edge is visited
edgesVisited++;
out.clear();
out.or(outgoing[e.tgt.getId()]);
if (out.cardinality() >= 2) {
for (int i = out.nextSetBit(0); i >= 0; i = out
.nextSetBit(i + 1)) {
// An edge is visited
edgesVisited++;
Edge runner = edges.get(i);
while (runner.id != e.postDominatorList.getLast().id) {
// An edge is visited
edgesVisited++;
runner.postDominanceFrontierSet.set(e.id);
runner = runner.postDominatorList.getLast();
}
}
}
}
}
示例14: observesDaylightTime
import java.util.BitSet; //导入方法依赖的package包/类
/**
* {@inheritDoc}
* @stable ICU 49
*/
@Override
public boolean observesDaylightTime() {
long time = System.currentTimeMillis();
// Check if daylight saving time is observed now.
int[] offsets = new int[2];
getOffset(time, false, offsets);
if (offsets[1] != 0) {
return true;
}
// If DST is not used now, check if DST is used after each transition.
BitSet checkFinals = finalRules == null ? null : new BitSet(finalRules.length);
while (true) {
TimeZoneTransition tt = getNextTransition(time, false);
if (tt == null) {
// no more transition
break;
}
TimeZoneRule toRule = tt.getTo();
if (toRule.getDSTSavings() != 0) {
return true;
}
if (checkFinals != null) {
// final rules exist - check if we saw all of them
for (int i = 0; i < finalRules.length; i++) {
if (finalRules[i].equals(toRule)) {
checkFinals.set(i);
}
}
if (checkFinals.cardinality() == finalRules.length) {
// already saw all final rules
break;
}
}
time = tt.getTime();
}
return false;
}
示例15: precomputedInternal
import java.util.BitSet; //导入方法依赖的package包/类
/**
* This is the actual implementation of {@link #precomputed}, but we bounce calls through a method
* on {@link Platform} so that we can have different behavior in GWT.
*
* <p>This implementation tries to be smart in a number of ways. It recognizes cases where the
* negation is cheaper to precompute than the matcher itself; it tries to build small hash tables
* for matchers that only match a few characters, and so on. In the worst-case scenario, it
* constructs an eight-kilobyte bit array and queries that. In many situations this produces a
* matcher which is faster to query than the original.
*/
@GwtIncompatible // SmallCharMatcher
CharMatcher precomputedInternal() {
final BitSet table = new BitSet();
setBits(table);
int totalCharacters = table.cardinality();
if (totalCharacters * 2 <= DISTINCT_CHARS) {
return precomputedPositive(totalCharacters, table, toString());
} else {
// TODO(lowasser): is it worth it to worry about the last character of large matchers?
table.flip(Character.MIN_VALUE, Character.MAX_VALUE + 1);
int negatedCharacters = DISTINCT_CHARS - totalCharacters;
String suffix = ".negate()";
final String description = toString();
String negatedDescription =
description.endsWith(suffix)
? description.substring(0, description.length() - suffix.length())
: description + suffix;
return new NegatedFastMatcher(
precomputedPositive(negatedCharacters, table, negatedDescription)) {
@Override
public String toString() {
return description;
}
};
}
}