本文整理汇总了Java中java.util.BitSet.flip方法的典型用法代码示例。如果您正苦于以下问题:Java BitSet.flip方法的具体用法?Java BitSet.flip怎么用?Java BitSet.flip使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.BitSet
的用法示例。
在下文中一共展示了BitSet.flip方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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("java.util.BitSet")
CharMatcher precomputedInternal() {
final BitSet table = new BitSet();
setBits(table);
int totalCharacters = table.cardinality();
if (totalCharacters * 2 <= DISTINCT_CHARS) {
return precomputedPositive(totalCharacters, table, description);
} else {
// TODO(user): 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()";
String negatedDescription = description.endsWith(suffix)
? description.substring(0, description.length() - suffix.length())
: description + suffix;
return new NegatedFastMatcher(toString(),
precomputedPositive(negatedCharacters, table, negatedDescription));
}
}
示例2: setBits
import java.util.BitSet; //导入方法依赖的package包/类
@GwtIncompatible("java.util.BitSet")
@Override
void setBits(BitSet table) {
BitSet tmp = new BitSet();
original.setBits(tmp);
tmp.flip(Character.MIN_VALUE, Character.MAX_VALUE + 1);
table.or(tmp);
}
示例3: initLiveOnEntrySets
import java.util.BitSet; //导入方法依赖的package包/类
private void initLiveOnEntrySets(OptFunctionNode fn, Node[] statementNodes)
{
int listLength = fn.getVarCount();
itsUseBeforeDefSet = new BitSet(listLength);
itsNotDefSet = new BitSet(listLength);
itsLiveOnEntrySet = new BitSet(listLength);
itsLiveOnExitSet = new BitSet(listLength);
for (int i = itsStartNodeIndex; i <= itsEndNodeIndex; i++) {
Node n = statementNodes[i];
lookForVariableAccess(fn, n);
}
itsNotDefSet.flip(0, listLength); // truth in advertising
}
示例4: 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;
}
};
}
}
示例5: setBits
import java.util.BitSet; //导入方法依赖的package包/类
@GwtIncompatible // used only from other GwtIncompatible code
@Override
void setBits(BitSet table) {
BitSet tmp = new BitSet();
original.setBits(tmp);
tmp.flip(Character.MIN_VALUE, Character.MAX_VALUE + 1);
table.or(tmp);
}
示例6: getIncludeRules
import java.util.BitSet; //导入方法依赖的package包/类
BitSet getIncludeRules(final SearchableString searchString, final Filter[] filters) {
final BitSet excludes = new BitSet(myRules.length);
for (final Filter filter : filters) {
filter.applyExcludes(searchString, excludes);
}
// Convert flip the excludes to determine the includes
final BitSet includes = excludes;
includes.flip(0, myRules.length);
return includes;
}
示例7: testExcludes
import java.util.BitSet; //导入方法依赖的package包/类
@Test
public void testExcludes() {
final int length = 1017;
final BitSet excludes = new BitSet(length);
final BitSet excludeFilter1 = new BitSet(length);
excludeFilter1.set(10);
excludeFilter1.set(20);
final BitSet excludeFilter2 = new BitSet(length);
excludeFilter1.set(20);
excludeFilter1.set(30);
excludes.or(excludeFilter1);
excludes.or(excludeFilter2);
assertEquals(3, excludes.cardinality());
excludes.flip(0, length);
assertEquals(length - 3, excludes.cardinality());
assertTrue(excludes.get(0));
assertTrue(excludes.get(length - 1));
assertFalse(excludes.get(10));
assertFalse(excludes.get(20));
assertFalse(excludes.get(30));
assertEquals(length - 1, excludes.nextSetBit(length - 1));
assertEquals(-1, excludes.nextSetBit(length));
}
示例8: readNext
import java.util.BitSet; //导入方法依赖的package包/类
public int readNext(InputStream is, byte[] buff, int patternLength,
BitSet eof, long[] posVector, SharedInputStream sin)
throws Exception {
int bufferLength = is.read(buffer, 0, patternLength);
if (bufferLength == -1) {
eof.flip(0);
} else if (bufferLength < patternLength) {
//repeatedly read patternLength - bufferLength
int temp = 0;
long pos = 0;
int i = bufferLength;
for (; i < patternLength; i++) {
if (sin != null) {
pos = sin.getPosition();
}
temp = is.read();
if (temp == -1) {
eof.flip(0);
if (sin != null) {
posVector[0] = pos;
}
break;
}
buffer[i] = (byte)temp;
}
bufferLength=i;
}
return bufferLength;
}
示例9: createPrimes
import java.util.BitSet; //导入方法依赖的package包/类
/**
* Create a {@code BitSet} wherein a set bit indicates the corresponding
* index plus 2 is prime. That is, if bit N is set, then the integer N + 2
* is prime. The values 0 and 1 are intentionally excluded. See the
* <a
* href="http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes#Algorithm_description">
* Sieve of Eratosthenes</a> algorithm description for more information.
*
* @param upperBound The maximum prime to allow
* @return bits indicating which indexes represent primes
*/
private static BitSet createPrimes(int upperBound) {
int nbits = upperBound - 1;
BitSet bs = new BitSet(nbits);
for (int p = 2; p * p < upperBound;) {
for (int i = p * p; i < nbits + 2; i += p) {
bs.set(i - 2, true);
}
do {
++p;
} while (p > 1 && bs.get(p - 2));
}
bs.flip(0, nbits);
return bs;
}
示例10: readNext
import java.util.BitSet; //导入方法依赖的package包/类
public int readNext(InputStream is, byte[] buff, int patternLength,
BitSet eof, long[] posVector, SharedInputStream sin)
throws Exception {
int bufferLength = is.read(buffer, 0, patternLength);
if (bufferLength == -1) {
eof.flip(0);
} else if (bufferLength < patternLength) {
//repeatedly read patternLength - bufferLength
int temp = 0;
long pos = 0;
int i = bufferLength;
for (; i < patternLength; i++) {
if (sin != null) {
pos = sin.getPosition();
}
temp = is.read();
if (temp == -1) {
eof.flip(0);
if (sin != null) {
posVector[0] = pos;
}
break;
}
buffer[i] = (byte) temp;
}
bufferLength = i;
}
return bufferLength;
}
示例11: main
import java.util.BitSet; //导入方法依赖的package包/类
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int N = scan.nextInt();
int M = scan.nextInt();
BitSet B1 = new BitSet(N);
BitSet B2 = new BitSet(N);
while (M-- > 0) {
String str = scan.next();
int a = scan.nextInt();
int b = scan.nextInt();
switch (str) {
case "AND":
if (a == 1) {
B1.and(B2);
} else {
B2.and(B1);
}
break;
case "OR":
if (a == 1) {
B1.or(B2);
} else {
B2.or(B1);
}
break;
case "XOR":
if (a == 1) {
B1.xor(B2);
} else {
B2.xor(B1);
}
break;
case "FLIP":
if (a == 1) {
B1.flip(b);
} else {
B2.flip(b);
}
break;
case "SET":
if (a == 1) {
B1.set(b);
} else {
B2.set(b);
}
break;
default:
break;
}
System.out.println(B1.cardinality() + " " + B2.cardinality());
}
scan.close();
}
示例12: computeNeg
import java.util.BitSet; //导入方法依赖的package包/类
/** Returns the negation of a (bit) set. */
private BitSet computeNeg(BitSet arg) {
BitSet result = (BitSet) arg.clone();
result.flip(0, this.nodeCount);
return result;
}
示例13: main
import java.util.BitSet; //导入方法依赖的package包/类
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int m = in.nextInt();
BitSet b1 = new BitSet(n);
BitSet b2 = new BitSet(n);
for (int i = 0; i < m; i++) {
String op = in.next();
int a = in.nextInt();
int b = in.nextInt();
switch (op) {
case "AND":
if (a == 1) {
b1.and(b2);
} else {
b2.and(b1);
}
break;
case "OR":
if (a == 1) {
b1.or(b2);
} else {
b2.or(b1);
}
break;
case "XOR":
if (a == 1) {
b1.xor(b2);
} else {
b2.xor(b1);
}
break;
case "FLIP":
if (a == 1) {
b1.flip(b);
} else {
b2.flip(b);
}
break;
case "SET":
if (a == 1) {
b1.set(b);
} else {
b2.set(b);
}
break;
}
System.out.println(b1.cardinality() + " " + b2.cardinality());
}
}
示例14: flip
import java.util.BitSet; //导入方法依赖的package包/类
/**
* Flips whole bitset passed.
* @param bitSet
*/
public static void flip(BitSet bitSet) {
bitSet.flip(0, bitSet.length());
}