Example usage for java.util BitSet size

List of usage examples for java.util BitSet size

Introduction

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

Prototype

public int size() 

Source Link

Document

Returns the number of bits of space actually in use by this BitSet to represent bit values.

Usage

From source file:MainClass.java

public static void main(String args[]) {
    BitSet bites = new BitSet();
    bites.set(0);//from w  w w.  j a  v  a2s  .co m
    bites.set(1);
    bites.set(2);
    bites.set(3);

    System.out.println(bites.size());
    System.out.println(bites.length());
}

From source file:BitOHoney.java

public static void main(String args[]) {
    String names[] = { "Java", "Source", "and", "Support" };
    BitSet bits = new BitSet();
    for (int i = 0, n = names.length; i < n; i++) {
        if ((names[i].length() % 2) == 0) {
            bits.set(i);/*from   w  w w . ja  v a  2  s .  co m*/
        }
    }
    System.out.println(bits);
    System.out.println("Size : " + bits.size());
    System.out.println("Length: " + bits.length());
    for (int i = 0, n = names.length; i < n; i++) {
        if (!bits.get(i)) {
            System.out.println(names[i] + " is odd");
        }
    }
    BitSet bites = new BitSet();
    bites.set(0);
    bites.set(1);
    bites.set(2);
    bites.set(3);
    bites.andNot(bits);
    System.out.println(bites);
}

From source file:BitOHoney1.java

public static void main(String args[]) {
    String names[] = { "Hershey's Kisses", "Nestle's Crunch", "Snickers", "3 Musketeers", "Milky Way", "Twix",
            "Mr. Goodbar", "Crunchie", "Godiva", "Charleston Chew", "Cadbury's", "Lindt", "Aero", "Hebert",
            "Toberlone", "Smarties", "LifeSavers", "Riesen", "Goobers", "Raisenettes", "Nerds", "Tootsie Roll",
            "Sweet Tarts", "Cotton Candy" };
    BitSet bits = new BitSet();
    for (int i = 0, n = names.length; i < n; i++) {
        if ((names[i].length() % 2) == 0) {
            bits.set(i);/*from   w  ww .  j a  v a2 s . c om*/
        }
    }
    System.out.println(bits);
    System.out.println("Size  : " + bits.size());
    System.out.println("Length: " + bits.length());
    for (int i = 0, n = names.length; i < n; i++) {
        if (!bits.get(i)) {
            System.out.println(names[i] + " is odd");
        }
    }
    BitSet bites = new BitSet();
    bites.set(0);
    bites.set(1);
    bites.set(2);
    bites.set(3);
    bites.andNot(bits);
    System.out.println(bites);
}

From source file:Main.java

public static void main(String[] args) {

    BitSet bitset1 = new BitSet(8);
    BitSet bitset2 = new BitSet(8);

    // assign values to bitset1
    bitset1.set(0);/* ww w.  j ava2s. co  m*/
    bitset1.set(1);
    bitset1.set(2);

    // assign values to bitset2
    bitset2.set(2);
    bitset2.set(4);

    // print the sets
    System.out.println("Bitset1:" + bitset1);
    System.out.println("Bitset2:" + bitset2);

    // print the size of the bitsets
    System.out.println(bitset1.size());
    System.out.println(bitset2.size());
}

From source file:Main.java

static int[] bits2Ints(BitSet bs) {
    int[] temp = new int[bs.size() / 32];

    for (int i = 0; i < temp.length; i++)
        for (int j = 0; j < 32; j++)
            if (bs.get(i * 32 + j))
                temp[i] |= 1 << j;

    return temp;//from  w  w w  . j  a  v  a  2 s  .co  m
}

From source file:Main.java

/**
 * bit representation of a BitSet//from w  w  w  . ja  v  a 2 s  .c o m
 * suitable for dumps and debugging
 * @param b - the BitSet
 * @return string representing the bits (i.e. 011010010...)
 */
public static String bitSet2String(BitSet b) {
    int len = b.size();
    len = (len > 128) ? 128 : len;
    StringBuilder d = new StringBuilder(len);
    for (int i = 0; i < len; i++)
        d.append(b.get(i) ? '1' : '0');
    return d.toString();
}

From source file:Main.java

public static byte[] toByteArray(BitSet bitSet) {
    byte[] array = new byte[bitSet.size() / 8 + 1];

    for (int i = bitSet.nextSetBit(0); i >= 0; i = bitSet.nextSetBit(i + 1)) {
        array[i / 8] |= byteMask(i);//from w w  w  .ja  v a  2 s  .  c  o m
    }

    return array;
}

From source file:com.cloudera.oryx.kmeans.computation.cluster.KSketchIndex.java

private static int hammingDistance(BitSet q, BitSet idx) {
    BitSet x = new BitSet(q.size());
    x.or(q);/*w w  w  .  ja  v a2 s.c  om*/
    x.xor(idx);
    return x.cardinality();
}

From source file:de.uniba.wiai.lspi.chord.data.ID.java

private static void partHashSet(final BitSet dst, final int dstOffset, final BitSet src, final int srcLen) {
    assert (dstOffset + srcLen <= dst.size());
    for (int i = 0; i < Math.min(src.size(), srcLen); ++i)
        dst.set(dstOffset + i, src.get(i));
}

From source file:de.uniba.wiai.lspi.chord.data.ID.java

private static BitSet bitsetResize(final BitSet a, final int numBits) {
    assert (numBits > 0);
    final BitSet b = new BitSet(numBits);
    for (int i = 0; i < Math.min(a.size(), numBits); ++i)
        b.set(i, a.get(i));//from   www . j  a va2s .c om

    return b;
}