当前位置: 首页>>代码示例>>Java>>正文


Java BitSet.cardinality方法代码示例

本文整理汇总了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);
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:25,代码来源:SmallCharMatcher.java

示例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.");
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:24,代码来源:B6296240.java

示例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;
    }
  }

}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:25,代码来源:NullComparator.java

示例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;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:33,代码来源:RegisterSpecList.java

示例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;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:GlobalLivenessAnalysisPhase.java

示例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();
    }
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:9,代码来源:BulkProcessorFutureCallback.java

示例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;
}
 
开发者ID:lagodiuk,项目名称:spoj,代码行数:33,代码来源:KRECT.java

示例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);
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:12,代码来源:CharMatcherBenchmark.java

示例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;
}
 
开发者ID:MikaGuraN,项目名称:HL4A,代码行数:9,代码来源:Block.java

示例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;
                }
            }
        }
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:41,代码来源:DomFront.java

示例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();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:MethodInvocation.java

示例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);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:9,代码来源:WhitespaceMatcherBenchmark.java

示例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();
				}
			}
		}
	}
}
 
开发者ID:guybrushPrince,项目名称:mojo.core,代码行数:30,代码来源:PostDominatorEdgeAnalysis.java

示例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;
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:44,代码来源:RuleBasedTimeZone.java

示例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;
      }
    };
  }
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:37,代码来源:CharMatcher.java


注:本文中的java.util.BitSet.cardinality方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。