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

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

源代码1 项目: netty-4.1.22   文件: CookieUtil.java
private static BitSet validCookieNameOctets(BitSet validCookieValueOctets) {
    BitSet bits = new BitSet(8);
    bits.or(validCookieValueOctets);
    bits.set('(', false);
    bits.set(')', false);
    bits.set('<', false);
    bits.set('>', false);
    bits.set('@', false);
    bits.set(':', false);
    bits.set('/', false);
    bits.set('[', false);
    bits.set(']', false);
    bits.set('?', false);
    bits.set('=', false);
    bits.set('{', false);
    bits.set('}', false);
    bits.set(' ', false);
    bits.set('\t', false);
    return bits;
}
 
源代码2 项目: kogito-runtimes   文件: HierarchyEncoderImpl.java
protected Set<HierNode<T>> gcs( Set<HierNode<T>> set ) {
    Set<HierNode<T>> s = new HashSet<HierNode<T>>();

    Iterator<HierNode<T>> iter = set.iterator();
    BitSet a = new BitSet( this.size() );
    a.or( iter.next().getBitMask() );
    while ( iter.hasNext() ) {
        a.and( iter.next().getBitMask() );
    }
    //System.out.println( "Root mask for ceil " + toBinaryString( a ) );
    for ( HierNode<T> node : getNodes() ) {
        if ( superset( node.getBitMask(), a ) >= 0 ) {
            s.add( node );
        }
    }

    Set<HierNode<T>> cl = ceil( s );
    return cl;
}
 
源代码3 项目: spotbugs   文件: MergeTree.java
public BitSet getTransitiveOutputSet(int input) {
    BitSet visited = new BitSet();
    BitSet result = new BitSet();

    LinkedList<Integer> workList = new LinkedList<>();
    workList.addLast(input);
    while (!workList.isEmpty()) {
        Integer valueNumber = workList.removeFirst();
        visited.set(valueNumber);
        BitSet outputSet = getOutputSet(valueNumber);
        result.or(outputSet);
        for (int i = outputSet.nextSetBit(0); i >= 0; i = outputSet.nextSetBit(i + 1)) {
            if (!visited.get(i)) {
                workList.addLast(i);
            }
        }
    }
    return result;
}
 
源代码4 项目: vtd-xml   文件: terminal_set.java
/** Determine if this set is an (improper) subset of another.
 * @param other the set we are testing against.
 */
public boolean is_subset_of(terminal_set other)
  throws internal_error
  {
    not_null(other);

    /* make a copy of the other set */
    BitSet copy_other = (BitSet)other._elements.clone();

    /* and or in */
    copy_other.or(_elements);

    /* if it hasn't changed, we were a subset */
    return copy_other.equals(other._elements);
  }
 
源代码5 项目: codebuff   文件: CharMatcher.java
@GwtIncompatible // java.util.BitSet
@Override
void setBits(BitSet table) {
    BitSet tmp1 = new BitSet();
    first.setBits(tmp1);
    BitSet tmp2 = new BitSet();
    second.setBits(tmp2);
    tmp1.and(tmp2);
    table.or(tmp1);
}
 
源代码6 项目: jadx   文件: LiveVarAnalysis.java
private void processLiveInfo() {
	int bbCount = mth.getBasicBlocks().size();
	int regsCount = mth.getRegsCount();
	BitSet[] liveInBlocks = initBitSetArray(bbCount, regsCount);
	List<BlockNode> blocks = mth.getBasicBlocks();
	int blocksCount = blocks.size();
	int iterationsLimit = blocksCount * 10;
	boolean changed;
	int k = 0;
	do {
		changed = false;
		for (BlockNode block : blocks) {
			int blockId = block.getId();
			BitSet prevIn = liveInBlocks[blockId];
			BitSet newIn = new BitSet(regsCount);
			for (BlockNode successor : block.getSuccessors()) {
				newIn.or(liveInBlocks[successor.getId()]);
			}
			newIn.andNot(defs[blockId]);
			newIn.or(uses[blockId]);
			if (!prevIn.equals(newIn)) {
				changed = true;
				liveInBlocks[blockId] = newIn;
			}
		}
		if (k++ > iterationsLimit) {
			throw new JadxRuntimeException("Live variable analysis reach iterations limit, blocks count: " + blocksCount);
		}
	} while (changed);

	this.liveIn = liveInBlocks;
}
 
public BitSet joinCode( Collection<BitSet> codes ) {
    BitSet x = new BitSet( this.size() );
    boolean first = true;
    for ( BitSet code : codes ) {
        if ( first ) {
            first = false;
            x.or( code );
        } else {
            x.and( code );
        }

    }
    return x;
}
 
源代码8 项目: tuffylite   文件: DataMover.java
/**
 *  sample one word from the real probability distribution
 * @param atoms
 * @param components
 * @return
 */
public BitSet SwordOfTruth(Collection<GAtom> atoms, ArrayList<Partition> parts){

	BitSet rs = new BitSet(atoms.size()+1);

	for(Partition p : parts){

		double logpdf = partLogPF.get(p);
		double sample = SeededRandom.getInstance().nextDouble();

		double acc = 0;
		BitSet bs = null;
		for(BitSet bs2 : wordLogPF.get(p).keySet()){
			double prob = Math.exp(wordLogPF.get(p).get(bs2) - logpdf);
			if(sample >= acc && sample <= acc + prob){
				bs = bs2;
				break;
			}
			acc = acc + prob;
		}

		rs.or(bs);

	}

	return rs;
}
 
源代码9 项目: codebuff   文件: CharMatcher.java
@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);
}
 
源代码10 项目: jadx   文件: RegionMaker.java
@Nullable
private static BlockNode calcPostDomOut(MethodNode mth, BlockNode block, List<BlockNode> exits) {
	if (exits.size() == 1 && mth.getExitBlocks().equals(exits)) {
		// simple case: for only one exit which is equal to method exit block
		return BlockUtils.calcImmediatePostDominator(mth, block);
	}
	// fast search: union of blocks dominance frontier
	// work if no fallthrough cases and no returns inside switch
	BitSet outs = BlockUtils.copyBlocksBitSet(mth, block.getDomFrontier());
	for (BlockNode s : block.getCleanSuccessors()) {
		outs.or(s.getDomFrontier());
	}
	outs.clear(block.getId());

	if (outs.cardinality() != 1) {
		// slow search: calculate partial post-dominance for every exit node
		BitSet ipdoms = BlockUtils.newBlocksBitSet(mth);
		for (BlockNode exitBlock : exits) {
			if (BlockUtils.isAnyPathExists(block, exitBlock)) {
				Set<BlockNode> pathBlocks = BlockUtils.getAllPathsBlocks(block, exitBlock);
				BlockNode ipdom = BlockUtils.calcPartialImmediatePostDominator(mth, block, pathBlocks, exitBlock);
				if (ipdom != null) {
					ipdoms.set(ipdom.getId());
				}
			}
		}
		outs.and(ipdoms);
	}
	return BlockUtils.bitSetToOneBlock(mth, outs);
}
 
public BitSet metMembersCode( Collection<H> vals ) {
    BitSet x = new BitSet( this.size() );
    for ( H val : vals ) {
        x.or( getNode( val ).getBitMask() );
    }
    return x;
}
 
源代码12 项目: tez   文件: DAGImpl.java
private BitSet computeVertexDescendants(BitSet verticesVisited, Vertex v) {
  int vertexIndex = v.getVertexId().getId();
  BitSet descendants = vertexDescendants.get(vertexIndex);
  if (!verticesVisited.get(vertexIndex)) {
    for (Vertex child : v.getOutputVertices().keySet()) {
      descendants.set(child.getVertexId().getId());
      BitSet childDescendants = computeVertexDescendants(verticesVisited, child);
      descendants.or(childDescendants);
    }
    verticesVisited.set(vertexIndex);
  }
  return descendants;
}
 
源代码13 项目: Box   文件: BlockProcessor.java
private static void calcDominators(List<BlockNode> basicBlocks, BlockNode entryBlock) {
	entryBlock.getDoms().clear();
	entryBlock.getDoms().set(entryBlock.getId());

	BitSet domSet = new BitSet(basicBlocks.size());
	boolean changed;
	do {
		changed = false;
		for (BlockNode block : basicBlocks) {
			if (block == entryBlock) {
				continue;
			}
			BitSet d = block.getDoms();
			if (!changed) {
				domSet.clear();
				domSet.or(d);
			}
			for (BlockNode pred : block.getPredecessors()) {
				d.and(pred.getDoms());
			}
			d.set(block.getId());
			if (!changed && !d.equals(domSet)) {
				changed = true;
			}
		}
	} while (changed);
}
 
BitSet prevKey( BitSet key ) {
    BitSet b = new BitSet( key.length() );
    b.or( key );
    int x = key.nextSetBit( 0 );
    if ( x == 0 ) {
        b.clear( 0 );
    } else {
        b.set( 0, x, true );
        b.clear( x );
    }
    return b;
}
 
源代码15 项目: api-mining   文件: SequenceTest.java
@Test
public void testSequenceGetCoveredWithGapsWithoutOverlap() {

	final Sequence trans = new Sequence(7, 3, 8, 9, 4, 5, 6, 8);

	final Sequence seq1 = new Sequence(3, 4, 5, 8);
	final BitSet expected1 = new BitSet(trans.size());
	expected1.set(1);
	expected1.set(4);
	expected1.set(5);
	expected1.set(7);

	final Sequence seq2 = new Sequence(7, 9);
	final BitSet expected2 = new BitSet(trans.size());
	expected2.set(0);
	expected2.set(3);

	final Sequence seq3 = new Sequence(8, 4, 5);
	final BitSet expected3 = new BitSet(trans.size());
	expected3.set(2);
	expected3.set(4);
	expected3.set(5);

	// Seq not contained in trans
	final Sequence seq4 = new Sequence(3, 3, 8);
	final BitSet expected4 = new BitSet(trans.size());

	assertEquals(expected1, trans.getCovered(seq1, new BitSet()));
	assertEquals(expected2, trans.getCovered(seq2, new BitSet()));
	assertEquals(expected2, trans.getCovered(seq2, expected1));
	assertEquals(expected3, trans.getCovered(seq3, new BitSet()));
	assertEquals(expected3, trans.getCovered(seq3, expected2));
	assertEquals(expected4, trans.getCovered(seq4, new BitSet()));

	// Test covering without overlap
	assertEquals(new BitSet(), trans.getCovered(seq3, expected1));

	// Test double covering
	final Sequence transC = new Sequence(1, 2, 1, 2, 1, 2);
	final Sequence seqC = new Sequence(1, 2);
	final BitSet expectedC1 = new BitSet(transC.size());
	expectedC1.set(0);
	expectedC1.set(1);
	final BitSet expectedC2 = new BitSet(transC.size());
	expectedC2.set(2);
	expectedC2.set(3);
	final BitSet expectedC3 = new BitSet(transC.size());
	expectedC3.set(4);
	expectedC3.set(5);

	assertEquals(expectedC1, transC.getCovered(seqC, new BitSet()));
	assertEquals(expectedC2, transC.getCovered(seqC, expectedC1));
	expectedC2.or(expectedC1);
	assertEquals(expectedC3, transC.getCovered(seqC, expectedC2));

	// Test covering with single item sequence
	final Sequence transI = new Sequence(12763, 12823, 34913);
	final Sequence seqI = new Sequence(34913);
	final BitSet expectedI = new BitSet(transI.size());
	expectedI.set(2);

	assertEquals(expectedI, transI.getCovered(seqI, new BitSet()));

}
 
源代码16 项目: metanome-algorithms   文件: FunctionalDependency.java
public BitSet getAttributes() {
	BitSet attributes = (BitSet) this.lhs.clone();
	attributes.or(this.rhs);
	return attributes;
}
 
源代码17 项目: tuffylite   文件: MRF.java
public Integer[] getClauseSat(BitSet world){

		Integer[] rs = new Integer[clauses.size()];

		for(int ct=0;ct<bitmaps_weight.length;ct++){

			rs[ct] = 0;

			double weight = bitmaps_weight[ct];

			BitSet signature = bitmaps_signature[ct];
			BitSet mask = bitmaps_mask[ct];

			// clause: c1 v !c2 v c3   (there are other atoms c4 and c5)
			//		=> 10100 as signature, 11100 as mask
			// given a world T
			// sat = \exists 1 in [ (T ^ 10100) v !(T v 10100) ] ^ 11100

			BitSet TandSIG = (BitSet) world.clone();
			TandSIG.and(signature);

			BitSet notTorSIG = (BitSet) world.clone();
			notTorSIG.or(signature);

			TandSIG.and(mask);
			BitSet tocheck = (BitSet) mask.clone();

			tocheck.andNot(notTorSIG);
			tocheck.or(TandSIG);

			// TODO: change to faster implementation of tally
			if(tocheck.isEmpty()){
				// tocheck == 000000... <--- false
				if(weight < 0){
					rs[ct] ++;
				}

			}else{
				// tocheck != 000000... <--- true
				if(weight > 0){
					rs[ct] ++;
				}
			}
		}

		return rs;
	}
 
源代码18 项目: HackerRank-solutions   文件: soln.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();
}
 
源代码19 项目: constellation   文件: TriangleUtilities.java
public static Tuple<Float, Float> countTrianglesTriplets(final GraphReadMethods graph) {
    final int vxCount = graph.getVertexCount();
    BitSet[] allNeighbours = new BitSet[vxCount];
    BitSet update = new BitSet(vxCount);
    Float triangles = 0f;
    Float triplets = 0f;

    // initialise variables
    for (int vxPosition = 0; vxPosition < vxCount; vxPosition++) {

        allNeighbours[vxPosition] = new BitSet(vxCount);

        // get the vertex ID at this position
        final int vxId = graph.getVertex(vxPosition);

        // collect neighbours
        BitSet neighbours = new BitSet(vxCount);
        for (int neighbourPosition = 0; neighbourPosition < graph.getVertexNeighbourCount(vxId); neighbourPosition++) {
            final int nxId = graph.getVertexNeighbour(vxId, neighbourPosition);
            final int nxPosition = graph.getVertexPosition(nxId);
            neighbours.set(nxPosition, true);
        }

        //not interested in neighbours to themselves
        neighbours.set(vxPosition, false);

        allNeighbours[vxPosition].or(neighbours);
        update.set(vxPosition, true);
    }

    // checking for triangles
    for (int one = update.nextSetBit(0); one >= 0; one = update.nextSetBit(one + 1)) {
        for (int two = update.nextSetBit(one); two >= one; two = update.nextSetBit(two + 1)) {
            // are these two vertices connected?
            if (allNeighbours[one].get(two) && allNeighbours[two].get(one)) {
                // determine common neighbours between them, each one is a triangle
                BitSet intersection = new BitSet(vxCount);
                intersection.or(allNeighbours[one]);
                intersection.and(allNeighbours[two]);
                for (int three = intersection.nextSetBit(two); three >= two; three = intersection.nextSetBit(three + 1)) {
                    triangles += 1;
                }
                BitSet union = new BitSet(vxCount);
                union.or(allNeighbours[one]);
                union.or(allNeighbours[two]);
                union.set(one, false);
                union.set(two, false);
                for (int three = union.nextSetBit(two); three >= two; three = union.nextSetBit(three + 1)) {
                    triplets += 1;
                }
            }
        }
    }

    return new Tuple<>(triangles, triplets);
}
 
源代码20 项目: JAADAS   文件: MultiRunStatementsFinder.java
protected void merge(BitSet in1, BitSet in2, BitSet out)
{
	out.clear();
	out.or(in1);
	out.or(in2);
}