Example usage for java.util BitSet or

List of usage examples for java.util BitSet or

Introduction

In this page you can find the example usage for java.util BitSet or.

Prototype

public void or(BitSet set) 

Source Link

Document

Performs a logical OR of this bit set with the bit set argument.

Usage

From source file:fingerprints.HashedBloomFingerprinter.java

private BitSet generateFingerprint(IAtomContainer container) {
    BitSet walkBits = bloomFilter.toBitSet();
    BitSet result = new BitSet(getFingerprintLength());
    result.or(walkBits);
    if (isRespectRingMatches()) {
        IRingSet rings = new RingSet();
        IRingSet allRings;/*from  w  ww . j a  v a 2  s  .  c  o  m*/
        try {
            allRings = arf.findAllRings(container);
            rings.add(allRings);
        } catch (CDKException e) {
            logger.debug(e.toString());
        }

        // sets SSSR information
        SSSRFinder finder = new SSSRFinder(container);
        IRingSet sssr = finder.findEssentialRings();
        rings.add(sssr);
        RingSetManipulator.markAromaticRings(rings);
        RingSetManipulator.sort(rings);
        setRingBits(result, rings);
    }
    bloomFilter.clear();
    return result;
}

From source file:de.hpi.petrinet.PetriNet.java

protected Map<Node, Set<Node>> deriveDominators(boolean reverse) {

    int initIndex = reverse ? this.getNodes().indexOf(this.getFinalPlace())
            : this.getNodes().indexOf(this.getInitialPlace());

    int size = this.getNodes().size();
    final BitSet[] dom = new BitSet[size];
    final BitSet ALL = new BitSet(size);

    for (Node n : this.getNodes())
        ALL.set(this.getNodes().indexOf(n));

    for (Node n : this.getNodes()) {
        int index = this.getNodes().indexOf(n);
        BitSet curDoms = new BitSet(size);
        dom[index] = curDoms;//ww w. j  av  a2s.  com

        if (index != initIndex)
            curDoms.or(ALL);
        else
            curDoms.set(initIndex);
    }

    boolean changed = true;

    /*
     * While we change the dom relation for a node
     */
    while (changed) {
        changed = false;
        for (Node n : this.getNodes()) {
            int index = this.getNodes().indexOf(n);
            if (index == initIndex)
                continue;

            final BitSet old = dom[index];
            final BitSet curDoms = new BitSet(size);
            curDoms.or(old);

            Collection<Node> predecessors = reverse ? n.getSucceedingNodes() : n.getPrecedingNodes();
            for (Node p : predecessors) {
                int index2 = this.getNodes().indexOf(p);
                curDoms.and(dom[index2]);
            }

            curDoms.set(index);

            if (!curDoms.equals(old)) {
                changed = true;
                dom[index] = curDoms;
            }
        }
    }

    Map<Node, Set<Node>> dominators = new HashMap<Node, Set<Node>>();

    for (Node n : this.getNodes()) {
        int index = this.getNodes().indexOf(n);
        dominators.put(n, new HashSet<Node>());
        for (int i = 0; i < size; i++)
            if (dom[index].get(i))
                dominators.get(n).add(this.getNodes().get(i));
    }

    return dominators;
}

From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.ExtractCommonOperatorsRule.java

private void getAllBlockingClusterIds(int clusterId, BitSet blockingClusters) {
    BitSet waitFor = clusterWaitForMap.get(clusterId);
    if (waitFor != null) {
        for (int i = waitFor.nextSetBit(0); i >= 0; i = waitFor.nextSetBit(i + 1)) {
            getAllBlockingClusterIds(i, blockingClusters);
        }//from  w w  w .  j a v a 2s  .  c  o  m
        blockingClusters.or(waitFor);
    }
}

From source file:android.databinding.tool.expr.ExprModelTest.java

private void assertFlags(Expr a, Expr... exprs) {
    BitSet bitSet = a.getShouldReadFlags();
    for (Expr expr : exprs) {
        BitSet clone = (BitSet) bitSet.clone();
        clone.and(expr.getInvalidFlags());
        assertEquals("should read flags of " + a.getUniqueKey() + " should include " + expr.getUniqueKey(),
                expr.getInvalidFlags(), clone);
    }// w w  w. java2s  .  c  o m

    BitSet composite = new BitSet();
    for (Expr expr : exprs) {
        composite.or(expr.getInvalidFlags());
    }
    assertEquals("composite flags should match", composite, bitSet);
}

From source file:AnalysisModule.DataAnalysis.java

protected void bitmapAnalyse(List<Scenario> lstScenario) throws Exception {
    BitMap bitMap;/*w  w  w. j av a2 s  . co m*/
    String bmpDir;
    int traffic;
    int numberOfFiles;
    FileInputStream fin = null;
    ObjectInputStream ois = null;

    for (Scenario scenario : lstScenario) {
        for (Topology topology : scenario.lstTopology) {
            for (Instance instance : topology.getLstInstance()) {
                instance.trafficMatrix = new double[topology.getNumberOfSwitches()][topology
                        .getNumberOfSwitches()];
            }
        }
    }

    for (Scenario scenario : lstScenario) {
        for (Topology topology : scenario.lstTopology) {
            System.out.println("Analisando Topologia: " + topology.getIdTopology());
            for (Instance instance : topology.getLstInstance()) {
                System.out.println("           Instancia: " + instance.getId());
                for (int i = 0; i < topology.getNumberOfSwitches(); i++) {
                    for (int j = 0; j < topology.getNumberOfSwitches(); j++) {
                        switch (instance.type) {
                        case BITMAP: {
                            if (j <= i) {
                                break;
                            }
                            TreeMap<Long, BitMap> sourceBitMapTree = new TreeMap<>();
                            TreeMap<Long, BitMap> destinationBitMapTree = new TreeMap<>();

                            bmpDir = getSrcDir(instance, i);
                            numberOfFiles = new File(bmpDir).listFiles().length - 1;
                            int firstBitmap = -2;

                            for (int numberOfBmp = 0; numberOfBmp < numberOfFiles; numberOfBmp++) {

                                fin = new FileInputStream(bmpDir + "BitMap" + numberOfBmp + ".bmp");
                                ois = new ObjectInputStream(fin);
                                bitMap = (BitMap) ois.readObject();

                                if ((bitMap.getStartEpoch() - 21600000000L > scenario.startTime)
                                        && (bitMap.getStartEpoch() - 21600000000L < scenario.endTime)) {
                                    if (firstBitmap == -2) {
                                        firstBitmap = numberOfBmp - 1;
                                    }
                                    sourceBitMapTree.put(bitMap.getStartEpoch() - 21600000000L, bitMap);

                                }

                                ois.close();
                                fin.close();
                            }

                            //Add the first bitmap in the Measurement Interval
                            if (firstBitmap >= 0) {
                                fin = new FileInputStream(bmpDir + "BitMap" + firstBitmap + ".bmp");
                                ois = new ObjectInputStream(fin);
                                bitMap = (BitMap) ois.readObject();

                                sourceBitMapTree.put(bitMap.getStartEpoch() - 21600000000L, bitMap);
                                ois.close();
                                fin.close();

                            }

                            bmpDir = getDestDir(instance, j);
                            numberOfFiles = new File(bmpDir).listFiles().length - 1;
                            firstBitmap = -2;

                            for (int numberOfBmp = 0; numberOfBmp < numberOfFiles; numberOfBmp++) {

                                fin = new FileInputStream(bmpDir + "BitMap" + numberOfBmp + ".bmp");
                                ois = new ObjectInputStream(fin);
                                bitMap = (BitMap) ois.readObject();

                                if ((bitMap.getStartEpoch() - 21600000000L > scenario.startTime)
                                        && (bitMap.getStartEpoch() - 21600000000L < scenario.endTime)) {
                                    if (firstBitmap == -2) {
                                        firstBitmap = numberOfBmp - 1;
                                    }
                                    destinationBitMapTree.put(bitMap.getStartEpoch() - 21600000000L, bitMap);
                                }
                                ois.close();
                                fin.close();
                            }

                            //Add the first bitmap in the Measurement Interval
                            if (firstBitmap >= 0) {
                                fin = new FileInputStream(bmpDir + "BitMap" + firstBitmap + ".bmp");
                                ois = new ObjectInputStream(fin);
                                bitMap = (BitMap) ois.readObject();

                                destinationBitMapTree.put(bitMap.getStartEpoch() - 21600000000L, bitMap);

                                ois.close();
                                fin.close();

                            }

                            //Estimation
                            int k1 = sourceBitMapTree.size();
                            int k2 = destinationBitMapTree.size();

                            Collection sourceEntrySet = sourceBitMapTree.entrySet();
                            Iterator sourceEntries = sourceEntrySet.iterator();

                            for (int q = 0; q < k1; q++) {
                                Map.Entry entrySrc = (Map.Entry) sourceEntries.next();
                                BitMap bmpSrc = (BitMap) entrySrc.getValue();

                                Collection destinationEntrySet = destinationBitMapTree.entrySet();
                                Iterator destinationEntries = destinationEntrySet.iterator();

                                for (int r = 0; r < k2; r++) {
                                    Map.Entry entryDst = (Map.Entry) destinationEntries.next();
                                    BitMap bmpDst = (BitMap) entryDst.getValue();

                                    boolean overlap = bmpSrc.getStartEpoch() <= bmpDst.getEndEpoch()
                                            && bmpSrc.getEndEpoch() >= bmpDst.getStartEpoch();

                                    if (overlap) {
                                        double sourceDTr = instance.getBitMapSize()
                                                * Math.log(((double) instance.getBitMapSize())
                                                        / (instance.getBitMapSize() - bmpSrc.occupancy()));

                                        double destinationDTr = instance.getBitMapSize()
                                                * Math.log(((double) instance.getBitMapSize())
                                                        / (instance.getBitMapSize() - bmpDst.occupancy()));

                                        BitSet orSrcDst = (BitSet) bmpSrc.getBitSet().clone();
                                        //BitSet andSrcDst = (BitSet) bmpSrc.getBitSet().clone();

                                        orSrcDst.or(bmpDst.getBitSet());
                                        //andSrcDst.and(bmpDst.getBitSet());
                                        double orDTr = instance.getBitMapSize()
                                                * Math.log(((double) instance.getBitMapSize())
                                                        / (instance.getBitMapSize() - orSrcDst.cardinality()));
                                        //double andDTr = instance.getBitMapSize() * Math.log(((double) instance.getBitMapSize()) / (instance.getBitMapSize() - andSrcDst.cardinality()));

                                        double estimation = 0D;
                                        if (Double.isFinite(orDTr)) {
                                            estimation = sourceDTr + destinationDTr - orDTr;
                                            //estimation = (bmpSrc.getNumberOfPackets()/sourceDTr) * estimation;
                                            //estimation = andDTr;
                                        }

                                        instance.trafficMatrix[i][j] += estimation;
                                    }
                                }
                            }
                            break;
                        }

                        case COUNTER_ARRAY: {
                            traffic = 0;
                            traffic += instance.networkSwitch.get(i).arrayCounter[i][j];
                            //traffic += instance.networkSwitch.get(i).arrayCounter[j][i];
                            instance.doCalculateMatrixElem(i, j, topology, traffic);
                            break;
                        }

                        case OPT_COUNTER_ARRAY: {
                            traffic = 0;
                            for (Integer node : topology.getPathNodes(i, j)) {
                                if (instance.networkSwitch.get(node).isObserver) {
                                    traffic += instance.networkSwitch.get(node).arrayCounter[i][j];
                                    //traffic += instance.networkSwitch.get(node).arrayCounter[j][i];
                                    break;
                                }
                            }
                            instance.doCalculateMatrixElem(i, j, topology, traffic);
                            break;
                        }
                        }
                    }
                }
            }
        }
    }
}

From source file:org.apache.kylin.cube.cuboid.algorithm.generic.BitsOnePointCrossover.java

/**
 * Helper for {@link #crossover(Chromosome, Chromosome)}. Performs the actual crossover.
 *
 * @param first  the first chromosome.//from   ww w  .  j av  a  2  s .c  om
 * @param second the second chromosome.
 * @return the pair of new chromosomes that resulted from the crossover.
 * @throws DimensionMismatchException if the length of the two chromosomes is different
 */
private ChromosomePair crossover(final BitsChromosome first, final BitsChromosome second)
        throws DimensionMismatchException {
    final int length = first.getLength();
    if (length != second.getLength()) {
        throw new DimensionMismatchException(second.getLength(), length);
    }

    final BitSet parent1Key = first.getRepresentation();
    final BitSet parent2Key = second.getRepresentation();

    final BitSet child1Key = new BitSet(length);
    final BitSet child2Key = new BitSet(length);

    // select a crossover point at random (0 and length makes no sense)
    final int crossoverIndex = 1 + (GeneticAlgorithm.getRandomGenerator().nextInt(length - 2));

    BitSet a = (BitSet) parent1Key.clone();
    a.clear(crossoverIndex, length);
    BitSet b = (BitSet) parent2Key.clone();
    b.clear(0, crossoverIndex);

    BitSet c = (BitSet) parent1Key.clone();
    c.clear(crossoverIndex, length);
    BitSet d = (BitSet) parent2Key.clone();
    d.clear(0, crossoverIndex);

    child1Key.or(a);
    child1Key.or(d);

    child2Key.or(c);
    child2Key.or(b);
    return new ChromosomePair(first.newBitsChromosome(child1Key), second.newBitsChromosome(child2Key));
}

From source file:org.apache.openjpa.kernel.DetachManager.java

/**
 * Ready the object for detachment, including loading the fields to be
 * detached and updating version information.
 *
 * @param idxs the indexes of fields to detach will be set as a side
 * effect of this method//from  w  ww .j  a  v a 2  s  .c om
 */
private static void preDetach(Broker broker, StateManagerImpl sm, BitSet idxs, boolean full,
        boolean reloadOnDetach) {
    // make sure the existing object has the right fields fetched; call
    // even if using currently-loaded fields for detach to make sure
    // version is set
    int detachMode = broker.getDetachState();
    int loadMode = StateManagerImpl.LOAD_FGS;
    BitSet exclude = null;
    if (detachMode == DETACH_LOADED)
        exclude = StoreContext.EXCLUDE_ALL;
    else if (detachMode == DETACH_ALL)
        loadMode = StateManagerImpl.LOAD_ALL;
    try {
        if (detachMode != DETACH_LOADED || reloadOnDetach || (!reloadOnDetach && !full)) {
            sm.load(broker.getFetchConfiguration(), loadMode, exclude, null, false);
        }
    } catch (ObjectNotFoundException onfe) {
        // consume the exception
    }

    // create bitset of fields to detach; if mode is all we can use
    // currently loaded bitset clone, since we know all fields are loaded
    if (idxs != null) {
        if (detachMode == DETACH_FETCH_GROUPS)
            setFetchGroupFields(broker, sm, idxs);
        else
            idxs.or(sm.getLoaded());

        // clear lrs fields
        FieldMetaData[] fmds = sm.getMetaData().getFields();
        for (int i = 0; i < fmds.length; i++)
            if (fmds[i].isLRS())
                idxs.clear(i);
    }
}

From source file:org.asoem.greyfish.utils.collect.BitString.java

protected final BitString standardOr(final BitString other) {
    final BitSet bitSetCopy = this.bitSet();
    bitSetCopy.or(other.bitSet());
    return BitString.create(bitSetCopy, Math.max(size(), other.size()));
}

From source file:org.roaringbitmap.TestRoaringBitmap.java

public void rTest(final int N) {
    System.out.println("rtest N=" + N);
    for (int gap = 1; gap <= 65536; gap *= 2) {
        final BitSet bs1 = new BitSet();
        final RoaringBitmap rb1 = new RoaringBitmap();
        for (int x = 0; x <= N; x += gap) {
            bs1.set(x);//www .  j a v  a  2 s  .c  o m
            rb1.add(x);
        }
        if (bs1.cardinality() != rb1.getCardinality())
            throw new RuntimeException("different card");
        if (!equals(bs1, rb1))
            throw new RuntimeException("basic  bug");
        for (int offset = 1; offset <= gap; offset *= 2) {
            final BitSet bs2 = new BitSet();
            final RoaringBitmap rb2 = new RoaringBitmap();
            for (int x = 0; x <= N; x += gap) {
                bs2.set(x + offset);
                rb2.add(x + offset);
            }
            if (bs2.cardinality() != rb2.getCardinality())
                throw new RuntimeException("different card");
            if (!equals(bs2, rb2))
                throw new RuntimeException("basic  bug");

            BitSet clonebs1;
            // testing AND
            clonebs1 = (BitSet) bs1.clone();
            clonebs1.and(bs2);
            if (!equals(clonebs1, RoaringBitmap.and(rb1, rb2)))
                throw new RuntimeException("bug and");
            {
                final RoaringBitmap t = rb1.clone();
                t.and(rb2);
                if (!equals(clonebs1, t))
                    throw new RuntimeException("bug inplace and");
                if (!t.equals(RoaringBitmap.and(rb1, rb2))) {
                    System.out.println(t.highLowContainer.getContainerAtIndex(0).getClass().getCanonicalName());
                    System.out.println(RoaringBitmap.and(rb1, rb2).highLowContainer.getContainerAtIndex(0)
                            .getClass().getCanonicalName());

                    throw new RuntimeException("bug inplace and");
                }
            }

            // testing OR
            clonebs1 = (BitSet) bs1.clone();
            clonebs1.or(bs2);

            if (!equals(clonebs1, RoaringBitmap.or(rb1, rb2)))
                throw new RuntimeException("bug or");
            {
                final RoaringBitmap t = rb1.clone();
                t.or(rb2);
                if (!equals(clonebs1, t))
                    throw new RuntimeException("bug or");
                if (!t.equals(RoaringBitmap.or(rb1, rb2)))
                    throw new RuntimeException("bug or");
                if (!t.toString().equals(RoaringBitmap.or(rb1, rb2).toString()))
                    throw new RuntimeException("bug or");

            }
            // testing XOR
            clonebs1 = (BitSet) bs1.clone();
            clonebs1.xor(bs2);
            if (!equals(clonebs1, RoaringBitmap.xor(rb1, rb2))) {
                throw new RuntimeException("bug xor");
            }
            {
                final RoaringBitmap t = rb1.clone();
                t.xor(rb2);
                if (!equals(clonebs1, t))
                    throw new RuntimeException("bug xor");
                if (!t.equals(RoaringBitmap.xor(rb1, rb2)))
                    throw new RuntimeException("bug xor");
            }
            // testing NOTAND
            clonebs1 = (BitSet) bs1.clone();
            clonebs1.andNot(bs2);
            if (!equals(clonebs1, RoaringBitmap.andNot(rb1, rb2))) {
                throw new RuntimeException("bug andnot");
            }
            clonebs1 = (BitSet) bs2.clone();
            clonebs1.andNot(bs1);
            if (!equals(clonebs1, RoaringBitmap.andNot(rb2, rb1))) {
                throw new RuntimeException("bug andnot");
            }
            {
                final RoaringBitmap t = rb2.clone();
                t.andNot(rb1);
                if (!equals(clonebs1, t)) {
                    throw new RuntimeException("bug inplace andnot");
                }
                final RoaringBitmap g = RoaringBitmap.andNot(rb2, rb1);
                if (!equals(clonebs1, g)) {
                    throw new RuntimeException("bug andnot");
                }
                if (!t.equals(g))
                    throw new RuntimeException("bug");
            }
            clonebs1 = (BitSet) bs1.clone();
            clonebs1.andNot(bs2);
            if (!equals(clonebs1, RoaringBitmap.andNot(rb1, rb2))) {
                throw new RuntimeException("bug andnot");
            }
            {
                final RoaringBitmap t = rb1.clone();
                t.andNot(rb2);
                if (!equals(clonebs1, t)) {
                    throw new RuntimeException("bug andnot");
                }
                final RoaringBitmap g = RoaringBitmap.andNot(rb1, rb2);
                if (!equals(clonebs1, g)) {
                    throw new RuntimeException("bug andnot");
                }
                if (!t.equals(g))
                    throw new RuntimeException("bug");
            }
        }
    }
}

From source file:uk.ac.ebi.atlas.experimentpage.baseline.genedistribution.BarChartTrader.java

protected int countGenesAboveCutoff(Map<FactorGroup, BitSet> geneBitSets, Set<Factor> filterFactors,
        Set<Factor> selectedFactors) {
    BitSet expressedGenesBitSet = new BitSet(AVERAGE_GENES_IN_EXPERIMENT);

    // get the union of genes expressed for all FactorGroups that are in the slice and have been selected
    for (FactorGroup factorGroup : geneBitSets.keySet()) {

        boolean factorGroupContainsAllFilterFactors = CollectionUtils.isEmpty(filterFactors)
                || factorGroup.containsAll(filterFactors);
        boolean factorGroupOverlapsSelectedFactors = CollectionUtils.isEmpty(selectedFactors)
                || factorGroup.overlapsWith(selectedFactors);

        if (factorGroupContainsAllFilterFactors && factorGroupOverlapsSelectedFactors) {
            expressedGenesBitSet.or(geneBitSets.get(factorGroup));
        }//w w  w  .j  a  v  a2  s.c  o m
    }
    return expressedGenesBitSet.cardinality();
}