flip ( )源码实例Demo

java.util.BitSet#flip ( )源码实例Demo

下面列出了java.util.BitSet#flip ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: gemfirexd-oss   文件: FunctionServiceTest.java
/**
 * Task to execute Random region Functions
 */
public static void doRandomFunctionExecutions(Region aRegion) {
  Set prKeys = getSomeKeys(aRegion);
  BitSet funcKey = new BitSet(funcKeys.length);
  funcKey.flip(KEYS_FIRST_OP, KEYS_LAST_OP + 1);
  HashSet keySet = ((FunctionServiceTest)testInstance).getKeySet(funcKey,
      prKeys);
  BitSet funcArg = new BitSet(funcArgs.length);
  funcArg.flip(ARGS_FIRST_OP, ARGS_LAST_OP + 1);
  String Args = ((FunctionServiceTest)testInstance).getArgs(funcArg);
  BitSet funcResultCollector = new BitSet(funcResultCollectors.length);
  funcResultCollector.flip(COLLECTOR_FIRST_OP, COLLECTOR_LAST_OP + 1);
  ResultCollector[] resultCollectors = ((FunctionServiceTest)testInstance)
      .getResultCollectors(funcResultCollector);
  BitSet funcDataSet = new BitSet(funcDataSets.length);
  funcDataSet.flip(DATASET_FIRST_OP, DATASET_LAST_OP + 1);
  Execution[] dataSets = ((FunctionServiceTest)testInstance).getDataSets(
      funcDataSet, aRegion);
  doRandomFunctions(keySet, Args, resultCollectors, dataSets);
}
 
源代码2 项目: gemfirexd-oss   文件: FunctionServiceTest.java
/**
 * Task to execute Random region Functions
 */
public static void doRandomFunctionExecutions(Region aRegion) {
  Set prKeys = getSomeKeys(aRegion);
  BitSet funcKey = new BitSet(funcKeys.length);
  funcKey.flip(KEYS_FIRST_OP, KEYS_LAST_OP + 1);
  HashSet keySet = ((FunctionServiceTest)testInstance).getKeySet(funcKey,
      prKeys);
  BitSet funcArg = new BitSet(funcArgs.length);
  funcArg.flip(ARGS_FIRST_OP, ARGS_LAST_OP + 1);
  String Args = ((FunctionServiceTest)testInstance).getArgs(funcArg);
  BitSet funcResultCollector = new BitSet(funcResultCollectors.length);
  funcResultCollector.flip(COLLECTOR_FIRST_OP, COLLECTOR_LAST_OP + 1);
  ResultCollector[] resultCollectors = ((FunctionServiceTest)testInstance)
      .getResultCollectors(funcResultCollector);
  BitSet funcDataSet = new BitSet(funcDataSets.length);
  funcDataSet.flip(DATASET_FIRST_OP, DATASET_LAST_OP + 1);
  Execution[] dataSets = ((FunctionServiceTest)testInstance).getDataSets(
      funcDataSet, aRegion);
  doRandomFunctions(keySet, Args, resultCollectors, dataSets);
}
 
源代码3 项目: kripton   文件: CharMatcher.java
/**
 * 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.
 *
 * @return the char matcher
 */
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(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()";
    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;
      }
    };
  }
}
 
源代码4 项目: TencentKona-8   文件: BMMimeMultipart.java
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;
}
 
源代码5 项目: kogito-runtimes   文件: HierarchyEncoderImpl.java
BitSet singleBitDiff( BitSet x, BitSet y ) {
    BitSet t = new BitSet( x.length() );
    t.or( x );
    t.flip(0, t.size());
    t.and( y );

    switch ( t.cardinality() ) {
        case 0 : return t;
        case 1 : return t;
        default: return new BitSet();
    }
}
 
源代码6 项目: codebuff   文件: CharMatcher.java
/**
 * 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, 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;
      }
    };
  }
}
 
/**
 * Hydra task to execute functions, then stop scheduling.
 */
public static void HydraTask_doFunctionExecution() {
  PdxTest.initClassLoader();
  BitSet availableOps = new BitSet(operations.length);
  availableOps.flip(FIRST_OP, LAST_OP + 1);
  ((ExecutionAndColocationTest)testInstance)
      .doFunctionExecution(availableOps);
  if (availableOps.cardinality() == 0) {
    ParRegBB.getBB().getSharedCounters().increment(ParRegBB.TimeToStop);
    throw new StopSchedulingTaskOnClientOrder("Finished with ops");
  }
}
 
源代码8 项目: incubator-iotdb   文件: RegularDataEncoder.java
private void data2Diff(long[] missingPointData) {
  bitmap = new BitSet(newBlockSize);
  bitmap.flip(0, newBlockSize);
  int offset = 0;
  for (int i = 1; i < missingPointData.length; i++) {
    long delta = missingPointData[i] - missingPointData[i - 1];
    if (delta != minDeltaBase) {
      int missingPointNum = (int) (delta / minDeltaBase) - 1;
      for (int j = 0; j < missingPointNum; j++) {
        bitmap.set(i + (offset++), false);
      }
    }
  }
}
 
源代码9 项目: jdk8u60   文件: BMMimeMultipart.java
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;
}
 
源代码10 项目: codebuff   文件: CharMatcher.java
/**
 * 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, 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;
      }
    };
  }
}
 
源代码11 项目: openjdk-8-source   文件: BMMimeMultipart.java
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;
}
 
源代码12 项目: codebuff   文件: CharMatcher.java
/**
 * 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, 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;
      }
    };
  }
}
 
源代码13 项目: browscap-java   文件: UserAgentParserTest.java
@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));
}
 
源代码14 项目: metanome-algorithms   文件: Inductor.java
public void updatePositiveCover(FDList nonFds) {
/*		if (nonFds.isEmpty())
			return;
		
		// Sort the negative cover
		Logger.getInstance().writeln("Sorting FD-violations ...");
		Collections.sort(nonFds, new Comparator<BitSet>() {
			@Override
			public int compare(BitSet o1, BitSet o2) {
				return (int)(o1.cardinality() - o2.cardinality());
			}
		});
*/		// THE SORTING IS NOT NEEDED AS THE UCCSet SORTS THE NONUCCS BY LEVEL ALREADY
		
		de.metanome.algorithms.cfdfinder.utils.Logger.getInstance().writeln("Inducing FD candidates ...");
		for (int i = nonFds.getFdLevels().size() - 1; i >= 0; i--) {
			if (i >= nonFds.getFdLevels().size()) // If this level has been trimmed during iteration
				continue;
			
			List<BitSet> nonFdLevel = nonFds.getFdLevels().get(i);
			for (BitSet lhs : nonFdLevel) {
				
				BitSet fullRhs = (BitSet) lhs.clone();
				fullRhs.flip(0, this.posCover.getNumAttributes());
				
				for (int rhs = fullRhs.nextSetBit(0); rhs >= 0; rhs = fullRhs.nextSetBit(rhs + 1))
					this.specializePositiveCover(lhs, rhs, nonFds);
			}
			nonFdLevel.clear();
		}
	}
 
源代码15 项目: gemfirexd-oss   文件: FixedPartitioningTest.java
/**
 * Hydra task to do region operations, then stop scheduling.
 */
public static void HydraTask_doOps() {
  BitSet availableOps = new BitSet(operations.length);
  availableOps.flip(FIRST_OP, LAST_OP + 1);
  ((FixedPartitioningTest)testInstance).doOps(availableOps);
  Log.getLogWriter().info("Cardinality is " + availableOps.cardinality());
  if (availableOps.cardinality() == 0) {
    ParRegBB.getBB().getSharedCounters().increment(ParRegBB.TimeToStop);
    throw new StopSchedulingTaskOnClientOrder("Finished with ops");
  }
}
 
源代码16 项目: gemfirexd-oss   文件: FunctionServiceTest.java
/**
 * Hydra task to execute region functions, then stop scheduling (For HA).
 */
public static void HydraTask_doFunctionExecution_HA() {
  BitSet availableOps = new BitSet(operations.length);
  availableOps.flip(FUNC_HA_FIRST_OP, FUNC_HA_LAST_OP + 1);
  ((FunctionServiceTest)testInstance).doFunctionExecution(availableOps);
  Log.getLogWriter().info("Cardinality is " + availableOps.cardinality());
  if (availableOps.cardinality() == 0) {
    ParRegBB.getBB().getSharedCounters().increment(ParRegBB.TimeToStop);
    throw new StopSchedulingTaskOnClientOrder("Finished with ops");
  }
}
 
源代码17 项目: openjdk-jdk9   文件: BMMimeMultipart.java
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;
}
 
源代码18 项目: JAADAS   文件: Insn3rc.java
private static BitSet getAllIncompatible(int regCount) {
	BitSet incompatRegs = new BitSet(regCount);
	incompatRegs.flip(0, regCount);
	return incompatRegs;
}
 
源代码19 项目: HackerRank-Solutions   文件: Java BitSet.java
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();
}
 
源代码20 项目: metanome-algorithms   文件: FindCoversGenerator.java
public List<FunctionalDependencyGroup2> execute(List<DifferenceSet> differenceSets, int numberOfAttributes)
        throws CouldNotReceiveResultException, ColumnNameMismatchException {

    if (this.timeMesurement) {
        this.startTime();
    }

    List<FunctionalDependencyGroup2> result = new LinkedList<FunctionalDependencyGroup2>();

    for (int attribute = 0; attribute < numberOfAttributes; attribute++) {

        List<DifferenceSet> tempDiffSet = new LinkedList<DifferenceSet>();

        // Compute DifferenceSet modulo attribute (line 3 - Fig5 - FastFDs)
        for (DifferenceSet ds : differenceSets) {
            BitSet obs = (BitSet) ds.getAttributes().clone();
            if (!obs.get(attribute)) {
                continue;
            }
            obs.flip(attribute);
            tempDiffSet.add(new DifferenceSet(obs));
        }

        // check new DifferenceSet (line 4 + 5 - Fig5 - FastFDs)
        if (tempDiffSet.size() == 0) {
            this.addFdToReceivers(new FunctionalDependencyGroup2(attribute, new IntArrayList()));
        } else if (this.checkNewSet(tempDiffSet)) {
            List<DifferenceSet> copy = new LinkedList<DifferenceSet>();
            copy.addAll(tempDiffSet);
            this.doRecusiveCrap(attribute, this.generateInitialOrdering(tempDiffSet), copy, new IntArrayList(), tempDiffSet,
                    result);
        }

    }

    if (this.timeMesurement) {
        this.stopTime();
    }

    return result;

}