Java Code Examples for java.util.BitSet#or()

The following examples show how to use java.util.BitSet#or() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MergeTree.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
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;
}
 
Example 2
Source File: HierarchyEncoderImpl.java    From kogito-runtimes with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 3
Source File: CookieUtil.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 4
Source File: CharMatcher.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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);
}
 
Example 5
Source File: BlockProcessor.java    From Box with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 6
Source File: DAGImpl.java    From tez with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 7
Source File: AbstractBitwiseHierarchyImpl.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
public BitSet metMembersCode( Collection<H> vals ) {
    BitSet x = new BitSet( this.size() );
    for ( H val : vals ) {
        x.or( getNode( val ).getBitMask() );
    }
    return x;
}
 
Example 8
Source File: AbstractBitwiseHierarchyImpl.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 9
Source File: RegionMaker.java    From jadx with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 10
Source File: DataMover.java    From tuffylite with Apache License 2.0 5 votes vote down vote up
/**
 *  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;
}
 
Example 11
Source File: AbstractBitwiseHierarchyImpl.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 12
Source File: LiveVarAnalysis.java    From jadx with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 13
Source File: CharMatcher.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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);
}
 
Example 14
Source File: terminal_set.java    From vtd-xml with GNU General Public License v2.0 5 votes vote down vote up
/** 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);
  }
 
Example 15
Source File: MRF.java    From tuffylite with Apache License 2.0 4 votes vote down vote up
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;
	}
 
Example 16
Source File: TriangleUtilities.java    From constellation with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example 17
Source File: MultiRunStatementsFinder.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
protected void merge(BitSet in1, BitSet in2, BitSet out)
{
	out.clear();
	out.or(in1);
	out.or(in2);
}
 
Example 18
Source File: soln.java    From HackerRank-solutions with MIT License 4 votes vote down vote up
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();
}
 
Example 19
Source File: FunctionalDependency.java    From metanome-algorithms with Apache License 2.0 4 votes vote down vote up
public BitSet getAttributes() {
	BitSet attributes = (BitSet) this.lhs.clone();
	attributes.or(this.rhs);
	return attributes;
}
 
Example 20
Source File: SequenceTest.java    From api-mining with GNU General Public License v3.0 4 votes vote down vote up
@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()));

}