本文整理了Java中java.util.BitSet.cardinality()
方法的一些代码示例,展示了BitSet.cardinality()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BitSet.cardinality()
方法的具体详情如下:
包路径:java.util.BitSet
类名称:BitSet
方法名:cardinality
[英]Returns the number of bits that are true in this BitSet.
[中]返回此位集中为真的位数。
代码示例来源:origin: skylot/jadx
public static List<BlockNode> bitSetToBlocks(MethodNode mth, BitSet bs) {
int size = bs.cardinality();
if (size == 0) {
return Collections.emptyList();
}
List<BlockNode> blocks = new ArrayList<>(size);
for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) {
BlockNode block = mth.getBasicBlocks().get(i);
blocks.add(block);
}
return blocks;
}
代码示例来源:origin: mpetazzoni/ttorrent
public PieceStorageImpl(TorrentByteStorage fileCollectionStorage,
BitSet availablePieces,
int piecesCount,
int pieceSize) {
this.fileCollectionStorage = fileCollectionStorage;
this.readWriteLock = new ReentrantReadWriteLock();
this.piecesCount = piecesCount;
this.pieceSize = pieceSize;
BitSet bitSet = new BitSet(piecesCount);
bitSet.or(availablePieces);
if (bitSet.cardinality() != piecesCount) {
this.availablePieces = bitSet;
}
isOpen = false;
}
代码示例来源:origin: google/guava
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);
}
代码示例来源:origin: apache/ignite
for (int j = 0; j < selectedNodesCnt; j++)
if ((mask & (1 << j)) != 0) {
boolean connected = connections[indexes[i]].get(indexes[j]);
BitSet resSet = new BitSet(selectedNodesCnt);
int idx = indexes[i];
assert selectedSet.get(idx)
: "Result contains node which is not presented in income set [nodeIdx" + idx + ", set=" + selectedSet + "]";
resSet.set(idx);
assert resSet.cardinality() > 0
: "No nodes selected as fully connected component [set=" + selectedSet + "]";
代码示例来源:origin: stackoverflow.com
BitSet temp2 = new BitSet();
temp2.set(j);
bitMap.put(temp1, temp2);
} else {
bitMap.get(temp1).set(j);
BitSet resultGetter = new BitSet(params[this.L]);
resultGetter.set(0, params[this.L] + 1, true);
Iterator<BitSet> itr = bitMap.keySet().iterator();
BitSet temp3 = new BitSet();
if (bitMap.get(temp3).cardinality() == params[this.N]) {
if (temp3.cardinality() <= resultGetter.cardinality()) {
resultGetter = temp3;
if (resultGetter.cardinality() > params[this.L])
retVal = -1;
else
retVal = resultGetter.cardinality();
代码示例来源:origin: apache/incubator-druid
private static <T> List<T> filterByBitset(List<T> list, BitSet bitSet)
{
final ArrayList<T> outList = new ArrayList<>(bitSet.cardinality());
for (int i = 0; i < list.size(); ++i) {
if (bitSet.get(i)) {
outList.add(list.get(i));
}
}
return outList;
}
代码示例来源:origin: apache/flink
@Override
public void invoke(Integer value) throws Exception {
numElements++;
if (duplicateChecker.get(value)) {
throw new Exception("Received a duplicate: " + value);
}
duplicateChecker.set(value);
if (numElements == numElementsTotal) {
// validate
if (duplicateChecker.cardinality() != numElementsTotal) {
throw new Exception("Duplicate checker has wrong cardinality");
}
else if (duplicateChecker.nextClearBit(0) != numElementsTotal) {
throw new Exception("Received sparse sequence");
}
else {
throw new SuccessException();
}
}
}
代码示例来源:origin: mpetazzoni/ttorrent
/**
* Piece download completion handler.
* <p/>
* <p>
* If the complete piece downloaded is valid, we can record in the torrent
* completedPieces bit field that we know have this piece.
* </p>
*
* @param peer The peer we got this piece from.
* @param piece The piece in question.
*/
@Override
public void handlePieceCompleted(SharingPeer peer,
Piece piece) throws IOException {
// Regardless of validity, record the number of bytes downloaded and
// mark the piece as not requested anymore
myTorrentStatistic.addDownloaded(piece.size());
this.requestedPieces.set(piece.getIndex(), false);
logger.trace("We now have {} piece(s) and {} outstanding request(s): {}",
new Object[]{
this.completedPieces.cardinality(),
this.requestedPieces.cardinality(),
this.requestedPieces
});
}
代码示例来源:origin: mpetazzoni/ttorrent
BitSet availablePieces = peer.getAvailablePieces();
for (int i = availablePieces.nextSetBit(0); i >= 0;
i = availablePieces.nextSetBit(i + 1)) {
this.pieces[i].noLongerAt(peer);
if (requested != null) {
for (Piece piece : requested) {
this.requestedPieces.set(piece.getIndex(), false);
new Object[]{
peer,
availablePieces.cardinality(),
this.completedPieces.cardinality(),
this.pieces.length
});
logger.trace("We now have {} piece(s) and {} outstanding request(s): {}",
new Object[]{
this.completedPieces.cardinality(),
this.requestedPieces.cardinality(),
this.requestedPieces
});
代码示例来源:origin: skylot/jadx
public static BlockNode getPathCross(MethodNode mth, BlockNode b1, BlockNode b2) {
if (b1 == null || b2 == null) {
return null;
}
BitSet b = new BitSet();
b.or(b1.getDomFrontier());
b.and(b2.getDomFrontier());
b.clear(b1.getId());
b.clear(b2.getId());
if (b.cardinality() == 1) {
BlockNode end = mth.getBasicBlocks().get(b.nextSetBit(0));
if (isPathExists(b1, end) && isPathExists(b2, end)) {
return end;
}
}
if (isPathExists(b1, b2)) {
return b2;
}
if (isPathExists(b2, b1)) {
return b1;
}
return null;
}
代码示例来源:origin: apache/ignite
BitSet canUse = new BitSet(selectedNodesCnt);
for (int i = 0; i < selectedNodesCnt; i++)
canUse.set(i);
if (bestRes != null && canUse.cardinality() <= bestRes.cardinality())
break;
BitSet currRes = new BitSet(selectedNodesCnt);
currRes.set(pickedIdx);
canUse.set(pickedIdx, false);
if (bestRes == null || currRes.cardinality() > bestRes.cardinality())
bestRes = currRes;
if (!bestRes.get(nodeIdx) && joinNode(bestRes, nodeIdx, nodeIndexes))
bestRes.set(nodeIdx);
BitSet reindexedBestRes = new BitSet(totalNodesCnt);
Iterator<Integer> it = new BitSetIterator(bestRes);
while (it.hasNext())
代码示例来源:origin: apache/ignite
/**
*
*/
@Test
public void testFind() {
BitSet[] matrix = provider.provide();
int nodes = matrix.length;
BitSet all = new BitSet(nodes);
for (int i = 0; i < nodes; i++)
all.set(i);
FullyConnectedComponentSearcher searcher = new FullyConnectedComponentSearcher(matrix);
BitSet res = searcher.findLargest(all);
int size = res.cardinality();
Assert.assertTrue("Actual = " + size + ", Expected = " + minAcceptableRes,
size >= minAcceptableRes);
}
代码示例来源:origin: linkedin/cruise-control
/**
* @return the number of windows with extrapolations.
*/
public synchronized int numWindowsWithExtrapolation() {
int currentIdx = arrayIndex(currentWindowIndex());
int numExtrapolationAdjustment = _extrapolations.get(currentIdx) ? 1 : 0;
return _extrapolations.cardinality() - numExtrapolationAdjustment;
}
代码示例来源:origin: mpetazzoni/ttorrent
/**
* Mark a piece as completed, decrementing the piece size in bytes from our
* left bytes to download counter.
*/
public synchronized void markCompleted(Piece piece) {
if (this.completedPieces.get(piece.getIndex())) {
return;
}
// A completed piece means that's that much data left to download for
// this torrent.
myTorrentStatistic.addLeft(-piece.size());
this.completedPieces.set(piece.getIndex());
if (completedPieces.cardinality() == getPiecesCount()) {
logger.info("all pieces are received for torrent {}. Validating...", this);
}
}
代码示例来源:origin: prestodb/presto
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);
}
代码示例来源:origin: mpetazzoni/ttorrent
/**
* Peer choked handler.
* <p/>
* <p>
* When a peer chokes, the requests made to it are canceled and we need to
* mark the eventually piece we requested from it as available again for
* download tentative from another peer.
* </p>
*
* @param peer The peer that choked.
*/
@Override
public synchronized void handlePeerChoked(SharingPeer peer) {
Set<Piece> pieces = peer.getRequestedPieces();
if (pieces.size() > 0) {
for (Piece piece : pieces) {
this.requestedPieces.set(piece.getIndex(), false);
}
}
logger.trace("Peer {} choked, we now have {} outstanding " +
"request(s): {}.",
new Object[]{
peer,
this.requestedPieces.cardinality(),
this.requestedPieces
});
}
代码示例来源:origin: google/guava
final BitSet table = new BitSet();
setBits(table);
int totalCharacters = table.cardinality();
if (totalCharacters * 2 <= DISTINCT_CHARS) {
return precomputedPositive(totalCharacters, table, toString());
代码示例来源:origin: apache/kylin
public ImmutableBitSet(BitSet set) {
this.set = (BitSet) set.clone();
this.arr = new int[set.cardinality()];
int j = 0;
for (int i = set.nextSetBit(0); i >= 0; i = set.nextSetBit(i + 1)) {
arr[j++] = i;
}
}
代码示例来源:origin: skylot/jadx
if (s.getIDom() != block) {
if (domFrontier == null) {
domFrontier = new BitSet(blocks.size());
domFrontier.set(s.getId());
for (int p = frontier.nextSetBit(0); p >= 0; p = frontier.nextSetBit(p + 1)) {
if (blocks.get(p).getIDom() != block) {
if (domFrontier == null) {
domFrontier = new BitSet(blocks.size());
domFrontier.set(p);
if (domFrontier == null || domFrontier.cardinality() == 0) {
domFrontier = EMPTY;
代码示例来源:origin: apache/hive
BitSet bs = new BitSet(numBuckets);
bs.clear();
PrimitiveObjectInspector bucketOI = (PrimitiveObjectInspector)bucketField.getFieldObjectInspector();
ObjectInspectorUtils.getBucketNumber(convCols, new ObjectInspector[]{constOI}, numBuckets) :
ObjectInspectorUtils.getBucketNumberOld(convCols, new ObjectInspector[]{constOI}, numBuckets);
bs.set(n);
if (bucketingVersion == 1 && ctxt.isCompat()) {
int h = ObjectInspectorUtils.getBucketHashCodeOld(convCols, new ObjectInspector[]{constOI});
bs.set(n);
if (bs.cardinality() < numBuckets) {
内容来源于网络,如有侵权,请联系作者删除!