本文整理了Java中java.util.BitSet
类的一些代码示例,展示了BitSet
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BitSet
类的具体详情如下:
包路径:java.util.BitSet
类名称:BitSet
[英]The BitSet class implements a bit array. Each element is either true or false. A BitSet is created with a given size and grows automatically if this size is exceeded.
[中]位集类实现了一个bit array。每个元素要么为真,要么为假。将使用给定的大小创建位集,如果超过此大小,位集将自动增长。
代码示例来源:origin: jenkinsci/jenkins
public ArgumentListBuilder prepend(String... args) {
// left-shift the mask
BitSet nm = new BitSet(this.args.size()+args.length);
for(int i=0; i<this.args.size(); i++)
nm.set(i+args.length, mask.get(i));
mask = nm;
this.args.addAll(0, Arrays.asList(args));
return this;
}
代码示例来源:origin: pxb1988/dex2jar
private void initExcludeColor(BitSet excludeColor, Reg as) {
excludeColor.clear();
for (Reg ex : as.excludes) {
if (ex.reg >= 0) {
excludeColor.set(ex.reg);
if (ex.type == 'J' || ex.type == 'D') {
excludeColor.set(ex.reg + 1);
}
}
}
}
代码示例来源:origin: apache/incubator-druid
/**
* Clear the info about which rows (in which original iterators and which row nums within them) were combined on
* the previous step.
*/
private void clearCombinedRowsInfo()
{
for (int originalIteratorIndex = indexesOfCurrentlyCombinedOriginalIterators.nextSetBit(0);
originalIteratorIndex >= 0;
originalIteratorIndex = indexesOfCurrentlyCombinedOriginalIterators.nextSetBit(originalIteratorIndex + 1)) {
minCurrentlyCombinedRowNumByOriginalIteratorIndex[originalIteratorIndex] =
MIN_CURRENTLY_COMBINED_ROW_NUM_UNSET_VALUE;
}
indexesOfCurrentlyCombinedOriginalIterators.clear();
}
代码示例来源:origin: google/guava
private BitSetMatcher(BitSet table, String description) {
super(description);
if (table.length() + Long.SIZE < table.size()) {
table = (BitSet) table.clone();
// If only we could actually call BitSet.trimToSize() ourselves...
}
this.table = table;
}
代码示例来源:origin: netty/netty
public void setCleanerFlag(int index) {
if (cleanerFlags == null) {
cleanerFlags = new BitSet();
}
cleanerFlags.set(index);
}
}
代码示例来源:origin: redisson/redisson
private static byte[] toByteArrayReverse(BitSet bits) {
byte[] bytes = new byte[bits.length() / 8 + 1];
for (int i = 0; i < bits.length(); i++) {
if (bits.get(i)) {
final int value = bytes[i / 8] | (1 << (7 - (i % 8)));
bytes[i / 8] = (byte) value;
}
}
return bytes;
}
代码示例来源:origin: apache/zeppelin
@Override
public void write(org.apache.thrift.protocol.TProtocol prot, appendOutput_args struct) throws org.apache.thrift.TException {
TTupleProtocol oprot = (TTupleProtocol) prot;
BitSet optionals = new BitSet();
if (struct.isSetEvent()) {
optionals.set(0);
}
oprot.writeBitSet(optionals, 1);
if (struct.isSetEvent()) {
struct.event.write(oprot);
}
}
代码示例来源:origin: apache/zeppelin
@Override
public void read(org.apache.thrift.protocol.TProtocol prot, getAllResources_result struct) throws org.apache.thrift.TException {
TTupleProtocol iprot = (TTupleProtocol) prot;
BitSet incoming = iprot.readBitSet(1);
if (incoming.get(0)) {
{
org.apache.thrift.protocol.TList _list29 = new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.STRING, iprot.readI32());
struct.success = new ArrayList<String>(_list29.size);
String _elem30;
for (int _i31 = 0; _i31 < _list29.size; ++_i31)
{
_elem30 = iprot.readString();
struct.success.add(_elem30);
}
}
struct.setSuccessIsSet(true);
}
}
}
代码示例来源:origin: apache/hive
@Override
public void read(org.apache.thrift.protocol.TProtocol prot, EnvironmentContext struct) throws org.apache.thrift.TException {
TTupleProtocol iprot = (TTupleProtocol) prot;
BitSet incoming = iprot.readBitSet(1);
if (incoming.get(0)) {
{
org.apache.thrift.protocol.TMap _map324 = new org.apache.thrift.protocol.TMap(org.apache.thrift.protocol.TType.STRING, org.apache.thrift.protocol.TType.STRING, iprot.readI32());
struct.properties = new HashMap<String,String>(2*_map324.size);
String _key325;
String _val326;
for (int _i327 = 0; _i327 < _map324.size; ++_i327)
{
_key325 = iprot.readString();
_val326 = iprot.readString();
struct.properties.put(_key325, _val326);
}
}
struct.setPropertiesIsSet(true);
}
}
}
代码示例来源:origin: stanfordnlp/CoreNLP
/** helper for gap encoding. */
private static byte[] bitSetToByteArray(BitSet bitSet) {
while (bitSet.length() % 8 != 0) { bitSet.set(bitSet.length(), true); }
byte[] array = new byte[bitSet.length()/8];
for (int i = 0; i < array.length; i++) {
int offset = i * 8;
int index = 0;
for (int j = 0; j < 8; j++) {
index <<= 1;
if (bitSet.get(offset+j)) { index++; }
}
array[i] = (byte)(index - 128);
}
return array;
}
代码示例来源:origin: apache/zeppelin
@Override
public void write(org.apache.thrift.protocol.TProtocol prot, getStatus_result struct) throws org.apache.thrift.TException {
TTupleProtocol oprot = (TTupleProtocol) prot;
BitSet optionals = new BitSet();
if (struct.isSetSuccess()) {
optionals.set(0);
}
oprot.writeBitSet(optionals, 1);
if (struct.isSetSuccess()) {
oprot.writeString(struct.success);
}
}
代码示例来源: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: spring-projects/spring-framework
private void doParse(String[] fields) {
setNumberHits(this.seconds, fields[0], 0, 60);
setNumberHits(this.minutes, fields[1], 0, 60);
setNumberHits(this.hours, fields[2], 0, 24);
setDaysOfMonth(this.daysOfMonth, fields[3]);
setMonths(this.months, fields[4]);
setDays(this.daysOfWeek, replaceOrdinals(fields[5], "SUN,MON,TUE,WED,THU,FRI,SAT"), 8);
if (this.daysOfWeek.get(7)) {
// Sunday can be represented as 0 or 7
this.daysOfWeek.set(0);
this.daysOfWeek.clear(7);
}
}
代码示例来源:origin: google/guava
@Override
void setBits(BitSet table) {
if (containsZero) {
table.set(0);
}
for (char c : this.table) {
if (c != 0) {
table.set(c);
}
}
}
}
代码示例来源:origin: apache/zeppelin
@Override
public void write(org.apache.thrift.protocol.TProtocol prot, resourceGet_result struct) throws org.apache.thrift.TException {
TTupleProtocol oprot = (TTupleProtocol) prot;
BitSet optionals = new BitSet();
if (struct.isSetSuccess()) {
optionals.set(0);
}
oprot.writeBitSet(optionals, 1);
if (struct.isSetSuccess()) {
oprot.writeBinary(struct.success);
}
}
代码示例来源: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/zeppelin
@Override
public void write(org.apache.thrift.protocol.TProtocol prot, getProgress_result struct) throws org.apache.thrift.TException {
TTupleProtocol oprot = (TTupleProtocol) prot;
BitSet optionals = new BitSet();
if (struct.isSetSuccess()) {
optionals.set(0);
}
oprot.writeBitSet(optionals, 1);
if (struct.isSetSuccess()) {
oprot.writeI32(struct.success);
}
}
代码示例来源:origin: google/guava
@Override
public boolean matches(char c) {
return table.get(c);
}
代码示例来源:origin: google/guava
@GwtIncompatible // java.util.BitSet
private void doTestSetBits(CharMatcher matcher) {
BitSet bitset = new BitSet();
matcher.setBits(bitset);
for (int i = Character.MIN_VALUE; i <= Character.MAX_VALUE; i++) {
assertEquals(matcher.matches((char) i), bitset.get(i));
}
}
代码示例来源: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);
}
内容来源于网络,如有侵权,请联系作者删除!