下面列出了java.util.EmptyStackException#java.util.BitSet 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void write(org.apache.thrift.protocol.TProtocol prot, PutRequestMessage struct) throws org.apache.thrift.TException {
TTupleProtocol oprot = (TTupleProtocol) prot;
struct.header.write(oprot);
oprot.writeString(struct.storeName);
oprot.writeBinary(struct.key);
BitSet optionals = new BitSet();
if (struct.isSetVersionedValue()) {
optionals.set(0);
}
if (struct.isSetValue()) {
optionals.set(1);
}
oprot.writeBitSet(optionals, 2);
if (struct.isSetVersionedValue()) {
struct.versionedValue.write(oprot);
}
if (struct.isSetValue()) {
oprot.writeBinary(struct.value);
}
}
SelectionRowFilter(final Graph graph, final GraphElementType et) {
selected = new BitSet();
final ReadableGraph rg = graph.getReadableGraph();
try {
final boolean isVertex = et == GraphElementType.VERTEX;
final int count = isVertex ? rg.getVertexCount() : rg.getTransactionCount();
final int selectedId = rg.getAttribute(et, (isVertex ? VisualConcept.VertexAttribute.SELECTED : VisualConcept.TransactionAttribute.SELECTED).getName());
for (int position = 0; position < count; position++) {
final int id = isVertex ? rg.getVertex(position) : rg.getTransaction(position);
final boolean isSelected = rg.getBooleanValue(selectedId, id);
if (isSelected) {
selected.set(position);
}
}
} finally {
rg.release();
}
}
@Override
public void write(libthrift091.protocol.TProtocol prot, queryConsumerGroup_result struct) throws libthrift091.TException {
TTupleProtocol oprot = (TTupleProtocol) prot;
BitSet optionals = new BitSet();
if (struct.isSetSuccess()) {
optionals.set(0);
}
if (struct.isSetE()) {
optionals.set(1);
}
oprot.writeBitSet(optionals, 2);
if (struct.isSetSuccess()) {
struct.success.write(oprot);
}
if (struct.isSetE()) {
struct.e.write(oprot);
}
}
private static void addTransitiveMatches(HollowReadStateEngine stateEngine, HollowMapTypeReadState typeState, Map<String, BitSet> matches) {
HollowMapSchema schema = typeState.getSchema();
BitSet matchingOrdinals = getOrCreateBitSet(matches, schema.getName(), typeState.maxOrdinal());
HollowTypeReadState keyTypeState = stateEngine.getTypeState(schema.getKeyType());
HollowTypeReadState valueTypeState = stateEngine.getTypeState(schema.getValueType());
BitSet keyOrdinals = getOrCreateBitSet(matches, schema.getKeyType(), keyTypeState.maxOrdinal());
BitSet valueOrdinals = getOrCreateBitSet(matches, schema.getValueType(), valueTypeState.maxOrdinal());
int ordinal = matchingOrdinals.nextSetBit(0);
while(ordinal != -1) {
HollowMapEntryOrdinalIterator iter = typeState.ordinalIterator(ordinal);
while(iter.next()) {
keyOrdinals.set(iter.getKey());
valueOrdinals.set(iter.getValue());
}
ordinal = matchingOrdinals.nextSetBit(ordinal + 1);
}
}
@Override
public ResultSetMetaData getMetaData() throws SQLException {
if (statement.getOperation().isMutation()) {
return null;
}
int paramCount = statement.getBindCount();
List<Object> params = this.getParameters();
BitSet unsetParams = new BitSet(statement.getBindCount());
for (int i = 0; i < paramCount; i++) {
if ( params.get(i) == BindManager.UNBOUND_PARAMETER) {
unsetParams.set(i);
params.set(i, null);
}
}
try {
// Just compile top level query without optimizing to get ResultSetMetaData
QueryPlan plan = statement.compilePlan(this, Sequence.ValueOp.VALIDATE_SEQUENCE);
return new PhoenixResultSetMetaData(this.getConnection(), plan.getProjector());
} finally {
int lastSetBit = 0;
while ((lastSetBit = unsetParams.nextSetBit(lastSetBit)) != -1) {
params.set(lastSetBit, BindManager.UNBOUND_PARAMETER);
lastSetBit++;
}
}
}
@Override
public void read(libthrift091.protocol.TProtocol prot, Record struct) throws libthrift091.TException {
TTupleProtocol iprot = (TTupleProtocol) prot;
BitSet incoming = iprot.readBitSet(3);
if (incoming.get(0)) {
struct.data = iprot.readBinary();
struct.setDataIsSet(true);
}
if (incoming.get(1)) {
struct.checksum = iprot.readI32();
struct.setChecksumIsSet(true);
}
if (incoming.get(2)) {
struct.eof = iprot.readBool();
struct.setEofIsSet(true);
}
}
private static List<BitSetWithID> extractPackedPrints(File f,int fileIndex){
final int sampleRate = Config.getInt(Key.RAFS_SAMPLE_RATE);//2250Hz Nyquist frequency
final int size = Config.getInt(Key.RAFS_FFT_SIZE);
final int overlap = size - Config.getInt(Key.RAFS_FFT_STEP_SIZE);
String file = f.getAbsolutePath();
AudioDispatcher d = AudioDispatcherFactory.fromPipe(file, sampleRate, size, overlap);
RafsExtractor ex = new RafsExtractor(file, true);
RafsPacker packer = new RafsPacker(ex,true);
//String baseName = f.getName();
d.setZeroPadFirstBuffer(true);
d.addAudioProcessor(ex);
d.addAudioProcessor(packer);
d.run();
List<BitSetWithID> prints = new ArrayList<>();
for (Map.Entry<Float, BitSet> frameEntry : packer.packedFingerprints.entrySet()) {
int offset = (int) (frameEntry.getKey() * 1000);
prints.add(new BitSetWithID(fileIndex * (1L<<32) + offset, frameEntry.getValue()));
}
return prints;
}
/**
* Creates map copy.
* @param from Source map.
* @param onlyActive Retains only active partitions.
*/
public GridPartitionStateMap(GridPartitionStateMap from, boolean onlyActive) {
size = from.size();
states = (BitSet)from.states.clone();
if (onlyActive) {
int part = 0;
int maxPart = states.size() / BITS;
while (part < maxPart) {
GridDhtPartitionState state = from.state(part);
if (state != null && !state.active())
remove(part);
part++;
}
}
}
protected Population initRandomPopulation(BitsChromosomeHelper helper) {
List<Chromosome> chromosomeList = Lists.newArrayListWithCapacity(populationSize);
while (chromosomeList.size() < populationSize) {
BitSet bitSetForSelection = new BitSet(helper.getLength());
//Initialize selection genes
double totalSpace = 0;
while (totalSpace < helper.spaceLimit) {
int j = org.apache.commons.math3.genetics.GeneticAlgorithm.getRandomGenerator()
.nextInt(helper.getLength());
if (!bitSetForSelection.get(j)) {
totalSpace += helper.getCuboidSizeByBitIndex(j);
bitSetForSelection.set(j);
}
}
Chromosome chromosome = new BitsChromosome(bitSetForSelection, benefitPolicy.getInstance(), helper);
chromosomeList.add(chromosome);
}
return new ElitisticListPopulation(chromosomeList, maxPopulationSize, 0.8);
}
/**
* Subsets of subsets subdivide correctly
*/
public void testRecursiveSubSets() throws Exception {
int setSize = expensiveTests ? 1000 : 100;
Class cl = ConcurrentSkipListSet.class;
NavigableSet<Integer> set = newSet(cl);
BitSet bs = new BitSet(setSize);
populate(set, setSize, bs);
check(set, 0, setSize - 1, true, bs);
check(set.descendingSet(), 0, setSize - 1, false, bs);
mutateSet(set, 0, setSize - 1, bs);
check(set, 0, setSize - 1, true, bs);
check(set.descendingSet(), 0, setSize - 1, false, bs);
bashSubSet(set.subSet(0, true, setSize, false),
0, setSize - 1, true, bs);
}
/**
* If feature is enabled, suppress warnings where there is at least one live
* store on the line where the warning would be reported.
*
* @param accumulator
* BugAccumulator containing warnings for method
* @param liveStoreSourceLineSet
* bitset of lines where at least one live store was seen
*/
private void suppressWarningsIfOneLiveStoreOnLine(BugAccumulator accumulator, BitSet liveStoreSourceLineSet) {
if (!SUPPRESS_IF_AT_LEAST_ONE_LIVE_STORE_ON_LINE) {
return;
}
// Eliminate any accumulated warnings for instructions
// that (due to inlining) *can* be live stores.
entryLoop: for (Iterator<? extends BugInstance> i = accumulator.uniqueBugs().iterator(); i.hasNext();) {
for (SourceLineAnnotation annotation : accumulator.locations(i.next())) {
if (liveStoreSourceLineSet.get(annotation.getStartLine())) {
// This instruction can be a live store; don't report
// it as a warning.
i.remove();
continue entryLoop;
}
}
}
}
@Override
public void write(org.apache.thrift.protocol.TProtocol prot, TListSentryPrivilegesByAuthResponse struct) throws org.apache.thrift.TException {
TTupleProtocol oprot = (TTupleProtocol) prot;
struct.status.write(oprot);
BitSet optionals = new BitSet();
if (struct.isSetPrivilegesMapByAuth()) {
optionals.set(0);
}
oprot.writeBitSet(optionals, 1);
if (struct.isSetPrivilegesMapByAuth()) {
{
oprot.writeI32(struct.privilegesMapByAuth.size());
for (Map.Entry<TSentryAuthorizable, TSentryPrivilegeMap> _iter127 : struct.privilegesMapByAuth.entrySet())
{
_iter127.getKey().write(oprot);
_iter127.getValue().write(oprot);
}
}
}
}
/**
* Returns an iterable over the bits in a bitmap that are set to '1'.
*
* <p>This allows you to iterate over a bit set using a 'foreach' construct.
* For instance:
*
* <blockquote><code>
* BitSet bitSet;<br>
* for (int i : Util.toIter(bitSet)) {<br>
* print(i);<br>
* }</code></blockquote>
*
* @param bitSet Bit set
* @return Iterable
*/
public static Iterable<Integer> toIter(final BitSet bitSet) {
return () -> new Iterator<Integer>() {
int i = bitSet.nextSetBit(0);
public boolean hasNext() {
return i >= 0;
}
public Integer next() {
int prev = i;
i = bitSet.nextSetBit(i + 1);
return prev;
}
public void remove() {
throw new UnsupportedOperationException();
}
};
}
private boolean writeRegisterInfo(IndentingWriter writer, BitSet registers) throws IOException {
int registerNum = registers.nextSetBit(0);
if (registerNum < 0) {
return false;
}
writer.write('#');
for (; registerNum >= 0; registerNum = registers.nextSetBit(registerNum + 1)) {
RegisterType registerType = analyzedInstruction.getPostInstructionRegisterType(registerNum);
registerFormatter.writeTo(writer, registerNum);
writer.write('=');
registerType.writeTo(writer);
writer.write(';');
}
return true;
}
private static void populateEquivalences(Map<Integer, BitSet> equivalence,
RexNode predicate) {
switch (predicate.getKind()) {
case EQUALS:
RexCall call = (RexCall) predicate;
final List<RexNode> operands = call.getOperands();
if (operands.get(0) instanceof RexInputRef) {
final RexInputRef ref0 = (RexInputRef) operands.get(0);
if (operands.get(1) instanceof RexInputRef) {
final RexInputRef ref1 = (RexInputRef) operands.get(1);
populateEquivalence(equivalence, ref0.getIndex(), ref1.getIndex());
populateEquivalence(equivalence, ref1.getIndex(), ref0.getIndex());
}
}
}
}
@Test
public void testRandomStream() {
final int size = 1024 * 1024;
final int[] seeds = {
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41,
43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
final byte[] bytes = new byte[size];
for (int seed : seeds) {
final Random random = new Random(seed);
random.nextBytes(bytes);
final BitSet bitSet = BitSet.valueOf(bytes);
final int cardinality = bitSet.cardinality();
final IntStream stream = bitSet.stream();
final int[] array = stream.toArray();
assertEquals(array.length, cardinality);
int nextSetBit = -1;
for (int i=0; i < cardinality; i++) {
nextSetBit = bitSet.nextSetBit(nextSetBit + 1);
assertEquals(array[i], nextSetBit);
}
}
}
@Override
public void read(libthrift091.protocol.TProtocol prot, TotalBill struct) throws libthrift091.TException {
TTupleProtocol iprot = (TTupleProtocol) prot;
BitSet incoming = iprot.readBitSet(2);
if (incoming.get(0)) {
struct.totalCost = iprot.readDouble();
struct.setTotalCostIsSet(true);
}
if (incoming.get(1)) {
{
libthrift091.protocol.TList _list5 = new libthrift091.protocol.TList(libthrift091.protocol.TType.STRUCT, iprot.readI32());
struct.billList = new ArrayList<BillItem>(_list5.size);
BillItem _elem6;
for (int _i7 = 0; _i7 < _list5.size; ++_i7)
{
_elem6 = new BillItem();
_elem6.read(iprot);
struct.billList.add(_elem6);
}
}
struct.setBillListIsSet(true);
}
}
@Override
public void destroyByteBuffer(long id, ByteBuffer bytebuf, ReclaimContext rctx) {
MemoryInfo mi = this.getMemPools().get((int)id);
FileChannel channel = mi.getFileChannel();
int startIdx, requiredblocks;
long handler, baseAddr;
try {
handler = getByteBufferHandler(id, bytebuf);
for (int blockIdx = 0; blockIdx < mi.getByteBufferBlocksList().size(); blockIdx++) {
BufferBlockInfo bufferBlock = mi.getByteBufferBlocksList().get(blockIdx);
if (bufferBlock.getChunkSizeMap().containsKey(handler)) {
BitSet chunksMap = bufferBlock.getBufferBlockChunksMap();
baseAddr = bufferBlock.getBufferBlockBaseAddress();
startIdx = (int)Math.floor((double)((handler - baseAddr) / CHUNK_BLOCK_SIZE));
requiredblocks = (int)Math.ceil((double)bytebuf.capacity() / CHUNK_BLOCK_SIZE);
markFree(chunksMap, startIdx, requiredblocks);
bufferBlock.getChunkSizeMap().remove(handler);
break;
}
}
} catch (Exception e) {
}
}
protected ClusterIdentifier buildClusterIdentifier(int recordId, int[][] invertedPlis, BitSet lhs, int lhsSize) {
int[] cluster = new int[lhsSize];
int index = 0;
for (int lhsAttr = lhs.nextSetBit(0); lhsAttr >= 0; lhsAttr = lhs.nextSetBit(lhsAttr + 1)) {
int clusterId = invertedPlis[lhsAttr][recordId];
if (clusterId < 0)
return null;
cluster[index] = clusterId;
index++;
}
return new ClusterIdentifier(cluster);
}
private static void computeDominators(MethodNode mth) {
List<BlockNode> basicBlocks = mth.getBasicBlocks();
int nBlocks = basicBlocks.size();
for (int i = 0; i < nBlocks; i++) {
BlockNode block = basicBlocks.get(i);
block.setId(i);
block.setDoms(new BitSet(nBlocks));
block.getDoms().set(0, nBlocks);
}
BlockNode entryBlock = mth.getEnterBlock();
calcDominators(basicBlocks, entryBlock);
markLoops(mth);
// clear self dominance
basicBlocks.forEach(block -> {
block.getDoms().clear(block.getId());
if (block.getDoms().isEmpty()) {
block.setDoms(EMPTY);
}
});
calcImmediateDominators(basicBlocks, entryBlock);
}
/**
* Submaps of submaps subdivide correctly
*/
public void testRecursiveSubMaps() throws Exception {
int mapSize = expensiveTests ? 1000 : 100;
Class cl = ConcurrentSkipListMap.class;
NavigableMap<Integer, Integer> map = newMap(cl);
bs = new BitSet(mapSize);
populate(map, mapSize);
check(map, 0, mapSize - 1, true);
check(map.descendingMap(), 0, mapSize - 1, false);
mutateMap(map, 0, mapSize - 1);
check(map, 0, mapSize - 1, true);
check(map.descendingMap(), 0, mapSize - 1, false);
bashSubMap(map.subMap(0, true, mapSize, false),
0, mapSize - 1, true);
}
/**
* Detects a JSR instruction and sets a flag to indicate we will need to do
* inlining.
*/
@Override
public void visitJumpInsn(final int opcode, final Label lbl) {
super.visitJumpInsn(opcode, lbl);
LabelNode ln = ((JumpInsnNode) instructions.getLast()).label;
if (opcode == JSR && !subroutineHeads.containsKey(ln)) {
subroutineHeads.put(ln, new BitSet());
}
}
@Override
public void read(org.apache.thrift.protocol.TProtocol prot, fetch_result struct) throws org.apache.thrift.TException {
TTupleProtocol iprot = (TTupleProtocol) prot;
BitSet incoming = iprot.readBitSet(1);
if (incoming.get(0)) {
struct.success = new FetchResponse();
struct.success.read(iprot);
struct.setSuccessIsSet(true);
}
}
@Override
public void read(org.apache.thrift.protocol.TProtocol prot, send_args struct) throws org.apache.thrift.TException {
TTupleProtocol iprot = (TTupleProtocol) prot;
BitSet incoming = iprot.readBitSet(2);
if (incoming.get(0)) {
struct.message = iprot.readString();
struct.setMessageIsSet(true);
}
if (incoming.get(1)) {
struct.param = iprot.readString();
struct.setParamIsSet(true);
}
}
/**
* Transfer connections from wg to inclusionGraph by creating a transaction
* for each link.
*
* @param wg Original graph.
* @param inclusionGraph Target graph.
* @param vertices Original vertex ids of interest.
*/
private void addTransactionsFromLinks(final GraphWriteMethods wg, final GraphWriteMethods inclusionGraph, final BitSet vertices) {
final int linkCount = wg.getLinkCount();
for (int position = 0; position < linkCount; position++) {
final int linkId = wg.getLink(position);
int lo = wg.getLinkLowVertex(linkId);
int hi = wg.getLinkHighVertex(linkId);
if (vertices.get(lo) && vertices.get(hi)) {
inclusionGraph.addTransaction(lo, hi, false);
}
}
}
private SCollection filterVertices(final Object callback) throws ScriptException {
final ScriptContext context = engine.getContext();
context.setAttribute("__func", callback, ScriptContext.ENGINE_SCOPE);
final BitSet vertices = new BitSet();
for (int vxId = elementIds.nextSetBit(0); vxId >= 0; vxId = elementIds.nextSetBit(vxId + 1)) {
context.setAttribute("__p1", new SVertex(readableGraph, vxId), ScriptContext.ENGINE_SCOPE);
final Object b = engine.eval("__func(__p1)");
if ((Boolean) b) {
vertices.set(vxId);
}
}
return new SCollection(engine, readableGraph, GraphElementType.VERTEX, vertices);
}
@Nullable
private BlockNode searchFallThroughCase(BlockNode successor, BlockNode out, BitSet caseBlocks) {
BitSet df = successor.getDomFrontier();
if (df.intersects(caseBlocks)) {
return getOneIntersectionBlock(out, caseBlocks, df);
}
Set<BlockNode> allPathsBlocks = BlockUtils.getAllPathsBlocks(successor, out);
Map<BlockNode, BitSet> bitSetMap = BlockUtils.calcPartialPostDominance(mth, allPathsBlocks, out);
BitSet pdoms = bitSetMap.get(successor);
if (pdoms != null && pdoms.intersects(caseBlocks)) {
return getOneIntersectionBlock(out, caseBlocks, pdoms);
}
return null;
}
private BitSet getRelatedTypesOnNonUnion(JSType type) {
// All of the types we encounter should have been added to the
// relatedBitsets via computeRelatedTypes.
if (relatedBitsets.containsKey(type)) {
return relatedBitsets.get(type);
} else {
throw new RuntimeException("Related types should have been computed for"
+ " type: " + type + " but have not been.");
}
}
/**
* Asserts that the documents returned by <code>q1</code>
* are a subset of those returned by <code>q2</code>.
*
* Both queries will be filtered by <code>filter</code>
*/
protected void assertSubsetOf(Query q1, Query q2, Query filter) throws Exception {
QueryUtils.check(q1);
QueryUtils.check(q2);
if (filter != null) {
q1 = new BooleanQuery.Builder()
.add(q1, Occur.MUST)
.add(filter, Occur.FILTER)
.build();
q2 = new BooleanQuery.Builder()
.add(q2, Occur.MUST)
.add(filter, Occur.FILTER)
.build();
}
// we test both INDEXORDER and RELEVANCE because we want to test needsScores=true/false
for (Sort sort : new Sort[] { Sort.INDEXORDER, Sort.RELEVANCE }) {
// not efficient, but simple!
TopDocs td1 = s1.search(q1, reader.maxDoc(), sort);
TopDocs td2 = s2.search(q2, reader.maxDoc(), sort);
assertTrue("too many hits: " + td1.totalHits.value + " > " + td2.totalHits.value, td1.totalHits.value <= td2.totalHits.value);
// fill the superset into a bitset
BitSet bitset = new BitSet();
for (int i = 0; i < td2.scoreDocs.length; i++) {
bitset.set(td2.scoreDocs[i].doc);
}
// check in the subset, that every bit was set by the super
for (int i = 0; i < td1.scoreDocs.length; i++) {
assertTrue(bitset.get(td1.scoreDocs[i].doc));
}
}
}
@Override
public void read(org.apache.thrift.protocol.TProtocol prot, UpdateResult struct) throws org.apache.thrift.TException {
TTupleProtocol iprot = (TTupleProtocol) prot;
BitSet incoming = iprot.readBitSet(4);
if (incoming.get(0)) {
struct.updateCount = iprot.readI32();
struct.setUpdateCountIsSet(true);
}
if (incoming.get(1)) {
{
org.apache.thrift.protocol.TList _list337 = new org.apache.thrift.protocol.TList(org.apache.thrift.protocol.TType.I32, iprot.readI32());
struct.batchUpdateCounts = new ArrayList<Integer>(_list337.size);
for (int _i338 = 0; _i338 < _list337.size; ++_i338)
{
int _elem339;
_elem339 = iprot.readI32();
struct.batchUpdateCounts.add(_elem339);
}
}
struct.setBatchUpdateCountsIsSet(true);
}
if (incoming.get(2)) {
struct.generatedKeys = new RowSet();
struct.generatedKeys.read(iprot);
struct.setGeneratedKeysIsSet(true);
}
if (incoming.get(3)) {
struct.warnings = new GFXDExceptionData();
struct.warnings.read(iprot);
struct.setWarningsIsSet(true);
}
}