Example usage for java.util BitSet BitSet

List of usage examples for java.util BitSet BitSet

Introduction

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

Prototype

private BitSet(long[] words) 

Source Link

Document

Creates a bit set using words as the internal representation.

Usage

From source file:bobs.is.compress.sevenzip.SevenZFile.java

private BitSet readAllOrBits(final DataInput header, final int size) throws IOException {
    final int areAllDefined = header.readUnsignedByte();
    final BitSet bits;
    if (areAllDefined != 0) {
        bits = new BitSet(size);
        for (int i = 0; i < size; i++) {
            bits.set(i, true);/*  w  ww  .  j a v  a  2 s.  c om*/
        }
    } else {
        bits = readBits(header, size);
    }
    return bits;
}

From source file:com.alibaba.android.layoutmanager.layoutmanager.StaggeredGridLayoutHelper.java

/**
 * Checks for gaps if we've reached to the top of the list.
 * <p/>//  w  w w  .  ja v  a  2 s .  c  o  m
 * Intermediate gaps created by full span items are tracked via mLaidOutInvalidFullSpan field.
 */
private View hasGapsToFix(VirtualLayoutManager layoutManager, final int position, final int alignLine) {
    View view = layoutManager.findViewByPosition(position);

    if (view == null) {
        return null;
    }

    BitSet mSpansToCheck = new BitSet(mNumLanes);
    mSpansToCheck.set(0, mNumLanes, true);

    for (Span span : mSpans) {
        if (span.mViews.size() != 0 && checkSpanForGap(span, layoutManager, alignLine)) {
            return layoutManager.getReverseLayout() ? span.mViews.get(span.mViews.size() - 1)
                    : span.mViews.get(0);
        }
    }

    // everything looks good
    return null;
}

From source file:bobs.is.compress.sevenzip.SevenZOutputFile.java

private void writeFileMTimes(final DataOutput header) throws IOException {
    int numLastModifiedDates = 0;
    for (final SevenZArchiveEntry entry : files) {
        if (entry.getHasLastModifiedDate()) {
            ++numLastModifiedDates;// w w  w.j ava 2  s .c o  m
        }
    }
    if (numLastModifiedDates > 0) {
        header.write(NID.kMTime);

        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        final DataOutputStream out = new DataOutputStream(baos);
        if (numLastModifiedDates != files.size()) {
            out.write(0);
            final BitSet mTimes = new BitSet(files.size());
            for (int i = 0; i < files.size(); i++) {
                mTimes.set(i, files.get(i).getHasLastModifiedDate());
            }
            writeBits(out, mTimes, files.size());
        } else {
            out.write(1); // "allAreDefined" == true
        }
        out.write(0);
        for (final SevenZArchiveEntry entry : files) {
            if (entry.getHasLastModifiedDate()) {
                out.writeLong(
                        Long.reverseBytes(SevenZArchiveEntry.javaTimeToNtfsTime(entry.getLastModifiedDate())));
            }
        }
        out.flush();
        final byte[] contents = baos.toByteArray();
        writeUint64(header, contents.length);
        header.write(contents);
    }
}

From source file:bobs.is.compress.sevenzip.SevenZFile.java

private BitSet readBits(final DataInput header, final int size) throws IOException {
    final BitSet bits = new BitSet(size);
    int mask = 0;
    int cache = 0;
    for (int i = 0; i < size; i++) {
        if (mask == 0) {
            mask = 0x80;/*from w w  w.  j  a  va2 s  .  c  o  m*/
            cache = header.readUnsignedByte();
        }
        bits.set(i, (cache & mask) != 0);
        mask >>>= 1;
    }
    return bits;
}

From source file:org.jax.haplotype.analysis.visualization.SimplePhylogenyTreeImageFactory.java

/**
 * Create a test tree/*from w  w w. jav  a 2  s  . co  m*/
 * @return
 *          the test tree
 */
@SuppressWarnings("all")
protected static PhylogenyTreeNode createTestTree() {
    PhylogenyTreeNode phylogenyTree = new PhylogenyTreeNode();
    phylogenyTree.getStrains().add("parent");

    PhylogenyTreeNode child = new PhylogenyTreeNode();
    child.getStrains().add("child strain1");
    PhylogenyTreeEdge phylogenyTreeEdge = new PhylogenyTreeEdge(new BitSet(0), child, 1.0);
    phylogenyTree.getChildEdges().add(phylogenyTreeEdge);

    PhylogenyTreeNode child2 = new PhylogenyTreeNode();
    //        child2.getStrains().add("child strain2");
    PhylogenyTreeEdge phylogenyTreeEdge2 = new PhylogenyTreeEdge(new BitSet(0), child2, 1.0);
    phylogenyTree.getChildEdges().add(phylogenyTreeEdge2);

    PhylogenyTreeNode child3 = new PhylogenyTreeNode();
    child3.getStrains().add("child strain3");
    PhylogenyTreeEdge phylogenyTreeEdge3 = new PhylogenyTreeEdge(new BitSet(0), child3, 1.0);
    phylogenyTree.getChildEdges().add(phylogenyTreeEdge3);

    PhylogenyTreeNode child4 = new PhylogenyTreeNode();
    child4.getStrains().add("child strain4");
    PhylogenyTreeEdge phylogenyTreeEdge4 = new PhylogenyTreeEdge(new BitSet(0), child4, 1.0);
    child3.getChildEdges().add(phylogenyTreeEdge4);

    PhylogenyTreeNode child5 = new PhylogenyTreeNode();
    child5.getStrains().add("child strain5");
    PhylogenyTreeEdge phylogenyTreeEdge5 = new PhylogenyTreeEdge(new BitSet(0), child5, 1.0);
    child3.getChildEdges().add(phylogenyTreeEdge5);

    PhylogenyTreeNode child8 = null;
    //        for(int i = 0; i < 12; i++)
    for (int i = 0; i < 6; i++) {
        child8 = new PhylogenyTreeNode();
        child8.getStrains().add("child strain6." + i);
        PhylogenyTreeEdge phylogenyTreeEdge8 = new PhylogenyTreeEdge(new BitSet(0), child8, 1.0);
        child2.getChildEdges().add(phylogenyTreeEdge8);
    }

    //        for(int i = 0; i < 15; i++)
    for (int i = 0; i < 10; i++) {
        PhylogenyTreeNode child9 = new PhylogenyTreeNode();
        child9.getStrains().add("child strain7." + i);
        PhylogenyTreeEdge phylogenyTreeEdge8 = new PhylogenyTreeEdgeWithRealValue(new BitSet(0), child9, 1.0,
                Math.random());
        child8.getChildEdges().add(phylogenyTreeEdge8);
        for (int j = 0; j < 10; j++) {
            child9.getStrains().add("strain8." + j);
        }
    }

    return phylogenyTree;
}

From source file:bobs.is.compress.sevenzip.SevenZOutputFile.java

private void writeFileWindowsAttributes(final DataOutput header) throws IOException {
    int numWindowsAttributes = 0;
    for (final SevenZArchiveEntry entry : files) {
        if (entry.getHasWindowsAttributes()) {
            ++numWindowsAttributes;//  w ww . j  a v a 2s.c  o  m
        }
    }
    if (numWindowsAttributes > 0) {
        header.write(NID.kWinAttributes);

        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
        final DataOutputStream out = new DataOutputStream(baos);
        if (numWindowsAttributes != files.size()) {
            out.write(0);
            final BitSet attributes = new BitSet(files.size());
            for (int i = 0; i < files.size(); i++) {
                attributes.set(i, files.get(i).getHasWindowsAttributes());
            }
            writeBits(out, attributes, files.size());
        } else {
            out.write(1); // "allAreDefined" == true
        }
        out.write(0);
        for (final SevenZArchiveEntry entry : files) {
            if (entry.getHasWindowsAttributes()) {
                out.writeInt(Integer.reverseBytes(entry.getWindowsAttributes()));
            }
        }
        out.flush();
        final byte[] contents = baos.toByteArray();
        writeUint64(header, contents.length);
        header.write(contents);
    }
}

From source file:srebrinb.compress.sevenzip.SevenZFile.java

private BitSet readAllOrBits(final ByteBuffer header, final int size) throws IOException {
    final int areAllDefined = getUnsignedByte(header);
    final BitSet bits;
    if (areAllDefined != 0) {
        bits = new BitSet(size);
        for (int i = 0; i < size; i++) {
            bits.set(i, true);/*from   w w w.  j a  v a 2  s  .co  m*/
        }
    } else {
        bits = readBits(header, size);
    }
    return bits;
}

From source file:srebrinb.compress.sevenzip.SevenZFile.java

private BitSet readBits(final ByteBuffer header, final int size) throws IOException {
    final BitSet bits = new BitSet(size);
    int mask = 0;
    int cache = 0;
    for (int i = 0; i < size; i++) {
        if (mask == 0) {
            mask = 0x80;//from   w ww  . ja  v  a 2s .  co  m
            cache = getUnsignedByte(header);
        }
        bits.set(i, (cache & mask) != 0);
        mask >>>= 1;
    }
    return bits;
}

From source file:org.apache.carbondata.hadoop.api.CarbonTableInputFormat.java

/**
 * set the matched partition indices into a BitSet
 * @param partitionIds  from alter table command, for normal query, it's null
 * @param filter   from query/*from ww  w. j  av  a  2s  .  c om*/
 * @param partitionInfo
 * @param oldPartitionIdList  only used in alter table command
 * @return
 */
private BitSet setMatchedPartitions(String partitionIds, Expression filter, PartitionInfo partitionInfo,
        List<Integer> oldPartitionIdList) {
    BitSet matchedPartitions = null;
    if (null != partitionIds) {
        String[] partList = partitionIds.replace("[", "").replace("]", "").split(",");
        // partList[0] -> use the first element to initiate BitSet, will auto expand later
        matchedPartitions = new BitSet(Integer.parseInt(partList[0].trim()));
        for (String partitionId : partList) {
            Integer index = oldPartitionIdList.indexOf(Integer.parseInt(partitionId.trim()));
            matchedPartitions.set(index);
        }
    } else {
        if (null != filter) {
            matchedPartitions = new FilterExpressionProcessor().getFilteredPartitions(filter, partitionInfo);
        }
    }
    return matchedPartitions;
}

From source file:juicebox.data.MatrixZoomData.java

/**
 * Dump the O/E or Pearsons matrix to standard out in ascii format.
 *
 * @param df   Density function (expected values)
 * @param type will be "oe", "pearsons", or "expected"
 * @param les  output stream/*from  ww w.j  a  v  a2  s.  c  om*/
 * @param pw   Text output stream
 * @throws java.io.IOException If fails to write
 */
public void dumpOE(ExpectedValueFunction df, String type, NormalizationType no, LittleEndianOutputStream les,
        PrintWriter pw) throws IOException {
    if (les == null && pw == null) {
        pw = new PrintWriter(System.out);
    }

    if (type.equals("oe")) {
        int nBins;

        if (zoom.getUnit() == HiC.Unit.BP) {
            nBins = chr1.getLength() / zoom.getBinSize() + 1;
        } else {
            nBins = ((DatasetReaderV2) reader).getFragCount(chr1) / zoom.getBinSize() + 1;
        }

        BasicMatrix matrix = new InMemoryMatrix(nBins);
        BitSet bitSet = new BitSet(nBins);

        List<Integer> blockNumbers = reader.getBlockNumbers(this);

        for (int blockNumber : blockNumbers) {
            Block b = null;
            try {
                b = reader.readNormalizedBlock(blockNumber, this, df.getNormalizationType());
                if (b != null) {
                    for (ContactRecord rec : b.getContactRecords()) {
                        int x = rec.getBinX();
                        int y = rec.getBinY();

                        int dist = Math.abs(x - y);
                        double expected = 0;
                        try {
                            expected = df.getExpectedValue(chr1.getIndex(), dist);
                        } catch (Exception e) {
                            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
                        }
                        double observed = rec.getCounts(); // Observed is already normalized
                        double normCounts = observed / expected;
                        // The apache library doesn't seem to play nice with NaNs
                        if (!Double.isNaN(normCounts)) {
                            matrix.setEntry(x, y, (float) normCounts);
                            if (x != y) {
                                matrix.setEntry(y, x, (float) normCounts);
                            }
                            bitSet.set(x);
                            bitSet.set(y);
                        }
                    }
                }
            } catch (IOException e) {
                e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
            }
        }

        if (les != null)
            les.writeInt(nBins);

        for (int i = 0; i < nBins; i++) {
            for (int j = 0; j < nBins; j++) {
                float output;
                if (!bitSet.get(i) && !bitSet.get(j)) {
                    output = Float.NaN;
                } else
                    output = matrix.getEntry(i, j);
                if (les != null)
                    les.writeFloat(output);
                else
                    pw.print(output + " ");
            }
            if (les == null)
                pw.println();
        }
        if (les == null) {
            pw.println();
            pw.flush();
        }
    } else {
        BasicMatrix pearsons = getPearsons(df);
        if (pearsons != null) {
            int dim = pearsons.getRowDimension();
            for (int i = 0; i < dim; i++) {
                for (int j = 0; j < dim; j++) {
                    float output = pearsons.getEntry(i, j);
                    if (les != null)
                        les.writeFloat(output);
                    else
                        pw.print(output + " ");
                }
                if (les == null)
                    pw.println();
            }
            pw.flush();
        } else {
            log.error("Pearson's not available at zoom " + zoom);
        }
    }
}