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:org.apache.openjpa.util.ArrayStateImage.java

/**
 * Create a new state image for the given number of fields.
 *///from  w  w  w .j  a  va2  s. co m
public static Object[] newImage(int numFields) {
    Object[] state = new Object[numFields + 1];
    state[numFields] = new BitSet(numFields);
    return state;
}

From source file:com.roche.sequencing.bioinformatics.common.utils.BitSetUtil.java

/**
 * converts a string to a bitset counting all 1's as true and all other characters as false
 * /*from ww  w .jav a  2s  . c om*/
 * @param bitsAsBinaryString
 * @return
 */
public static BitSet createBitSetFromBinaryString(String bitsAsBinaryString) {
    BitSet bitSet = new BitSet(bitsAsBinaryString.length());

    for (int i = 0; i < bitsAsBinaryString.length(); i++) {
        if (bitsAsBinaryString.substring(i, i + 1).equals("1")) {
            bitSet.set(i, true);
        } else {
            bitSet.set(i, false);
        }
    }

    return bitSet;
}

From source file:fr.tse.fi2.hpp.labs.queries.impl.lab5.BloomFilterQuery.java

public BloomFilterQuery(QueryProcessorMeasure measure) {
    super(measure);

    k = 10;//from  ww  w  .  ja  v  a2s .  c om
    bloomFilter = new BitSet(14378);
    salt = new String[k];
    for (int i = 0; i < k; i++) {
        salt[i] = RandomStringUtils.random(10);
    }

}

From source file:Main.java

/**
 * Converts a binary representation of a Bitmap field
 * into a Java BitSet/*from   w  w w  .j a v  a 2  s.  c o m*/
 * @param b - binary representation
 * @param offset - staring offset
 * @param maxBits - max number of bits (supports 64,128 or 192)
 * @return java BitSet object
 */
public static BitSet byte2BitSet(byte[] b, int offset, int maxBits) {
    int len = maxBits > 64 ? ((b[offset] & 0x80) == 0x80 ? 128 : 64) : maxBits;

    if (maxBits > 128 && b.length > offset + 8 && (b[offset + 8] & 0x80) == 0x80) {
        len = 192;
    }
    BitSet bmap = new BitSet(len);
    for (int i = 0; i < len; i++)
        if (((b[offset + (i >> 3)]) & (0x80 >> (i % 8))) > 0)
            bmap.set(i + 1);
    return bmap;
}

From source file:Main.java

/**
 * Converts an ASCII representation of a Bitmap field
 * into a Java BitSet/*from  w w w. jav a2 s.  co m*/
 * @param b - hex representation
 * @param offset - starting offset
 * @param maxBits - max number of bits (supports 8, 16, 24, 32, 48, 52, 64,.. 128 or 192)
 * @return java BitSet object
 */
public static BitSet hex2BitSet(byte[] b, int offset, int maxBits) {
    int len = maxBits > 64 ? ((Character.digit((char) b[offset], 16) & 0x08) == 8 ? 128 : 64) : maxBits;
    BitSet bmap = new BitSet(len);
    for (int i = 0; i < len; i++) {
        int digit = Character.digit((char) b[offset + (i >> 2)], 16);
        if ((digit & (0x08 >> (i % 4))) > 0) {
            bmap.set(i + 1);
            if (i == 65 && maxBits > 128)
                len = 192;
        }
    }
    return bmap;
}

From source file:com.google.uzaygezen.core.BitSetBackedBitVector.java

public BitSetBackedBitVector(int nbits) {
    this(nbits, new BitSet(nbits));
}

From source file:eu.crisis_economics.utilities.EnumDistribution.java

public static <T extends Enum<T>> EnumDistribution<T> // Immutable
        create(Class<T> token, String sourceFile) throws IOException {
    if (token == null)
        throw new NullArgumentException();
    if (!token.isEnum())
        throw new IllegalArgumentException("EnumDistribution: " + token.getSimpleName() + " is not an enum.");
    if (token.getEnumConstants().length == 0)
        throw new IllegalArgumentException("EnumDistribution: " + token.getSimpleName() + " is an empty enum.");
    EnumDistribution<T> result = new EnumDistribution<T>();
    result.values = token.getEnumConstants();
    result.probabilities = new EnumMap<T, Double>(token);
    Map<String, T> converter = new HashMap<String, T>();
    final int numberOfValues = result.values.length;
    int[] valueIndices = new int[numberOfValues];
    double[] valueProbabilities = new double[numberOfValues];
    BitSet valueIsComitted = new BitSet(numberOfValues);
    {//from   ww  w.  j a  v  a2  s . co m
        int counter = 0;
        for (T value : result.values) {
            valueIndices[counter] = counter++;
            result.probabilities.put(value, 0.);
            converter.put(value.name(), value);
        }
    }
    BufferedReader reader = new BufferedReader(new FileReader(sourceFile));
    try {
        String newLine;
        while ((newLine = reader.readLine()) != null) {
            if (newLine.isEmpty())
                continue;
            StringTokenizer tokenizer = new StringTokenizer(newLine);
            final String name = tokenizer.nextToken(" ,:\t"), pStr = tokenizer.nextToken(" ,:\t");
            if (tokenizer.hasMoreTokens())
                throw new ParseException(
                        "EnumDistribution: " + newLine + " is not a valid entry in " + sourceFile + ".", 0);
            final double p = Double.parseDouble(pStr);
            if (p < 0. || p > 1.)
                throw new IOException(pStr + " is not a valid probability for the value " + name);
            result.probabilities.put(converter.get(name), p);
            final int ordinal = converter.get(name).ordinal();
            if (valueIsComitted.get(ordinal))
                throw new ParseException("The value " + name + " appears twice in " + sourceFile, 0);
            valueProbabilities[converter.get(name).ordinal()] = p;
            valueIsComitted.set(ordinal, true);
        }
        { // Check sum of probabilities
            double sum = 0.;
            for (double p : valueProbabilities)
                sum += p;
            if (Math.abs(sum - 1.) > 1e2 * Math.ulp(1.))
                throw new IllegalStateException("EnumDistribution: parser has succeeded, but the resulting "
                        + "probaility sum (value " + sum + ") is not equal to 1.");
        }
    } catch (Exception e) {
        throw new IOException(e.getMessage());
    } finally {
        reader.close();
    }
    result.dice = new EnumeratedIntegerDistribution(valueIndices, valueProbabilities);
    return result;
}

From source file:com.l2jfree.gameserver.idfactory.BitSetRebuildFactory.java

public synchronized void initialize() {
    _log.info("starting db rebuild, good luck");
    _log.info("this will take a while, dont kill the process or power off youre machine!");
    try {//from ww  w.j  av a  2 s. c  o  m
        _freeIds = new BitSet(PrimeFinder.nextPrime(100000));
        _freeIds.clear();
        _freeIdCount = new AtomicInteger(FREE_OBJECT_ID_SIZE);
        List<Integer> used_ids = new FastList<Integer>();
        // first get all used ids
        for (int usedObjectId : extractUsedObjectIDTable())
            used_ids.add(usedObjectId);

        _nextFreeId = new AtomicInteger(_freeIds.nextClearBit(0));

        Connection con = null;
        con = L2DatabaseFactory.getInstance().getConnection(con);
        int nextid;
        int changedids = 0;
        // now loop through all already used oids and assign a new clean one
        for (int i : extractUsedObjectIDTable()) {
            for (;;) //danger ;)
            {
                nextid = getNextId();
                if (!used_ids.contains(nextid))
                    break;
            }
            for (String update : ID_UPDATES) {
                PreparedStatement ps = con.prepareStatement(update);
                ps.setInt(1, nextid);
                ps.setInt(2, i);
                ps.execute();
                ps.close();
                changedids++;
            }
        }
        _log.info(
                "database rebuild done, changed " + changedids + " ids, set idfactory config to BitSet! ^o^/");
        System.exit(0);
    } catch (Exception e) {
        _log.fatal("could not rebuild database! :", e);
        System.exit(0);
    }
}

From source file:stats.EntropyComputer.java

/**
 * Constructor// ww w . ja  v  a2 s . c o  m
 * 
 * @param nbInstances
 *            number of lines in the database
 * @param lattice
 *            associated lattice
 */
public EntropyComputer(int nbInstances, Lattice lattice) {
    this.lookup = new HashMap<BitSet, Double>();
    this.lattice = lattice;
    this.nbInstances = nbInstances;
    lookup.put(new BitSet(lattice.getNbVariables()), 0.0);
    this.partialEntropy = new double[this.nbInstances + 1];
    double lnN = log(nbInstances);
    partialEntropy[0] = 0.0;
    for (int i = 1; i < partialEntropy.length; i++) {
        partialEntropy[i] = i * (log(i) - lnN);
    }
    nbCellsEverParsed = 0;
}

From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.core.variable.BinaryVariable.java

/**
 * Constructs a binary variable with the specified number of bits. All bits
 * are initially set to {@code false}./*from   ww w  .j ava2s .  c o  m*/
 * 
 * @param numberOfBits the number of bits stored in this variable
 */
public BinaryVariable(int numberOfBits) {
    super();
    this.numberOfBits = numberOfBits;

    bitSet = new BitSet(numberOfBits);
}