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

public BitSet() 

Source Link

Document

Creates a new bit set.

Usage

From source file:com.textocat.textokit.morph.ruscorpora.DictionaryAligningTagMapper2.java

@Override
public void initialize(UimaContext ctx) throws ResourceInitializationException {
    ExternalResourceInitializer.initialize(this, ctx);
    ConfigurationParameterInitializer.initialize(this, ctx);
    dict = dictHolder.getDictionary();/*from   w  w  w. ja v a2  s .  c o m*/
    gm = dict.getGramModel();
    try {
        FileOutputStream os = FileUtils.openOutputStream(outFile);
        Writer bw = new BufferedWriter(new OutputStreamWriter(os, "utf-8"));
        out = new PrintWriter(bw);
    } catch (IOException e) {
        throw new ResourceInitializationException(e);
    }
    //
    rncDistortionsMask = new BitSet();
    rncDistortionsMask.set(gm.getGrammemNumId(Dist));
    rncDistortionsMask.set(gm.getGrammemNumId(RNCMorphConstants.RNC_Abbr));
    //
    rncTrimmer = new PosTrimmer(gm, POST, Anum, Apro, Prnt, GNdr, ANim, NMbr, CAse, Supr, ASpc, TRns, VOic,
            MOod, TEns, PErs, INvl, Name, Patr, Surn, Fixd, Dist, RNCMorphConstants.RNC_Abbr,
            RNCMorphConstants.RNC_INIT);
}

From source file:com.opengamma.analytics.math.minimization.NonLinearTransformFunctionTest.java

@Test
public void testNonLinearTransform() {
    BitSet fixed = new BitSet();
    DoubleMatrix1D start = new DoubleMatrix1D(new double[2]);
    UncoupledParameterTransforms transforms = new UncoupledParameterTransforms(start, TRANSFORMS, fixed);
    NonLinearTransformFunction transFunc = new NonLinearTransformFunction(FUNCTION, JACOBIAN, transforms);
    Function1D<DoubleMatrix1D, DoubleMatrix1D> func = transFunc.getFittingFunction();
    Function1D<DoubleMatrix1D, DoubleMatrix2D> jacFunc = transFunc.getFittingJacobian();

    VectorFieldFirstOrderDifferentiator diff = new VectorFieldFirstOrderDifferentiator();
    Function1D<DoubleMatrix1D, DoubleMatrix2D> jacFuncFD = diff.differentiate(func);

    DoubleMatrix1D testPoint = new DoubleMatrix1D(new double[] { 4.5, -2.1 });
    DoubleMatrix2D jac = jacFunc.evaluate(testPoint);
    DoubleMatrix2D jacFD = jacFuncFD.evaluate(testPoint);
    assertEquals(3, jac.getNumberOfRows());
    assertEquals(2, jac.getNumberOfColumns());

    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 2; j++) {
            assertEquals(jacFD.getEntry(i, j), jac.getEntry(i, j), 1e-6);
        }// www.ja  v  a  2  s  .c o  m
    }
}

From source file:org.apache.metron.stellar.common.utils.hashing.tlsh.TLSHHasher.java

public Map<String, String> bin(String hash) throws DecoderException {
    Random r = new Random(0);
    byte[] h = Hex.decodeHex(hash.substring(2 * checksumOption.getChecksumLength()).toCharArray());
    BitSet vector = BitSet.valueOf(h);
    int n = vector.length();
    Map<String, String> ret = new HashMap<>();
    boolean singleHash = hashes.size() == 1;
    for (int numHashes : hashes) {
        BitSet projection = new BitSet();
        for (int i = 0; i < numHashes; ++i) {
            int index = r.nextInt(n);
            projection.set(i, vector.get(index));
        }//from   w  w  w. j av  a  2s .  c  o  m
        String outputHash = numHashes + Hex.encodeHexString(projection.toByteArray());
        if (singleHash) {
            ret.put(TLSH_BIN_KEY, outputHash);
        } else {
            ret.put(TLSH_BIN_KEY + "_" + numHashes, outputHash);
        }
    }
    return ret;
}

From source file:com.opengamma.analytics.financial.model.volatility.smile.fitting.SmileModelFitter.java

/**
 * Solve using the default NonLinearParameterTransforms for the concrete implementation
 * @param start The first guess at the parameter values
 * @return The LeastSquareResults/*  ww  w  .  jav a 2  s  . c om*/
 */
public LeastSquareResultsWithTransform solve(final DoubleMatrix1D start) {
    return solve(start, new BitSet());
}

From source file:org.exoplatform.services.jcr.impl.core.query.lucene.CachingIndexReader.java

/**
 * Creates a new <code>CachingIndexReader</code> based on
 * <code>delegatee</code>//ww  w. j a  v  a 2s .co  m
 *
 * @param delegatee the base <code>IndexReader</code>.
 * @param cache     a document number cache, or <code>null</code> if not
 *                  available to this reader.
 * @param initCache if the {@link #parents} cache should be initialized
 *                  when this index reader is constructed.
 * @throws IOException if an error occurs while reading from the index.
 */
CachingIndexReader(IndexReader delegatee, DocNumberCache cache, boolean initCache) throws IOException {
    super(delegatee);
    this.cache = cache;
    this.parents = new DocId[delegatee.maxDoc()];
    this.shareableNodes = new BitSet();
    TermDocs tDocs = delegatee.termDocs(new Term(FieldNames.SHAREABLE_NODE, ""));
    try {
        while (tDocs.next()) {
            shareableNodes.set(tDocs.doc());
        }
    } finally {
        tDocs.close();
    }
    this.cacheInitializer = new CacheInitializer(delegatee);
    if (initCache) {
        cacheInitializer.run();
    }
    // limit cache to 1% of maxDoc(), but at least 10.
    this.docNumber2uuid = Collections.synchronizedMap(new LRUMap(Math.max(10, delegatee.maxDoc() / 100)));
    this.termDocsCache = new TermDocsCache(delegatee, FieldNames.PROPERTIES);
}

From source file:com.indeed.lsmtree.core.TestStore.java

public void testStore(StorageType storageType, CompressionCodec codec) throws Exception {
    File indexDir = new File(tmpDir, "index");
    indexDir.mkdirs();//  w  w  w .  j  a  va 2  s  .com
    File indexLink = new File(tmpDir, "indexlink");
    PosixFileOperations.link(indexDir, indexLink);
    File storeDir = new File(indexLink, "store");
    Store<Integer, Long> store = new StoreBuilder<Integer, Long>(storeDir, new IntSerializer(),
            new LongSerializer()).setMaxVolatileGenerationSize(8 * 1024 * 1024).setStorageType(storageType)
                    .setCodec(codec).build();
    final Random r = new Random(0);
    final int[] ints = new int[treeSize];
    for (int i = 0; i < ints.length; i++) {
        ints[i] = r.nextInt();
    }
    for (final int i : ints) {
        store.put(i, (long) i);
        assertTrue(store.get(i) == i);
    }
    for (final int i : ints) {
        assertTrue(store.get(i) == i);
    }
    store.close();
    store.waitForCompactions();
    store = new StoreBuilder<Integer, Long>(storeDir, new IntSerializer(), new LongSerializer())
            .setMaxVolatileGenerationSize(8 * 1024 * 1024).setStorageType(storageType).setCodec(codec).build();
    Arrays.sort(ints);
    Iterator<Store.Entry<Integer, Long>> iterator = store.iterator();
    int index = 0;
    while (iterator.hasNext()) {
        Store.Entry<Integer, Long> next = iterator.next();
        int current = ints[index];
        assertTrue(next.getKey() == ints[index]);
        assertTrue(next.getValue() == ints[index]);
        while (index < ints.length && ints[index] == current) {
            index++;
        }
    }
    assertTrue(index == ints.length);
    final BitSet deleted = new BitSet();
    for (int i = 0; i < ints.length / 10; i++) {
        int deletionIndex = r.nextInt(ints.length);
        deleted.set(deletionIndex, true);
        for (int j = deletionIndex - 1; j >= 0; j--) {
            if (ints[j] == ints[deletionIndex]) {
                deleted.set(j, true);
            } else {
                break;
            }
        }
        for (int j = deletionIndex + 1; j < ints.length; j++) {
            if (ints[j] == ints[deletionIndex]) {
                deleted.set(j, true);
            } else {
                break;
            }
        }
        store.delete(ints[deletionIndex]);
        assertNull(store.get(ints[deletionIndex]));
    }
    iterator = store.iterator();
    index = 0;
    while (iterator.hasNext()) {
        Store.Entry<Integer, Long> next = iterator.next();
        while (deleted.get(index))
            index++;
        int current = ints[index];
        assertTrue(next.getKey() == ints[index]);
        assertTrue(next.getValue() == ints[index]);
        while (index < ints.length && ints[index] == current) {
            index++;
        }
    }
    while (deleted.get(index))
        index++;
    assertTrue(index == ints.length);
    final int max = ints[ints.length - 1];
    final AtomicInteger done = new AtomicInteger(8);
    for (int i = 0; i < done.get(); i++) {
        final int thread = i;
        final Store<Integer, Long> finalStore = store;
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Random r = new Random(thread);
                    for (int i = 0; i < treeSize; i++) {
                        int rand = r.nextInt();
                        int insertionindex = Arrays.binarySearch(ints, rand);

                        Store.Entry<Integer, Long> next = finalStore.ceil(rand);
                        boolean found = next != null;
                        if (insertionindex >= 0 && deleted.get(insertionindex)) {
                            assertNull(finalStore.get(ints[insertionindex]));
                        } else {
                            assertTrue(found == (rand <= max));
                            if (found) {
                                assertTrue(next.getKey() >= rand);
                                assertTrue(next.getKey().longValue() == next.getValue());
                                if (insertionindex >= 0) {
                                    assertTrue(rand == ints[insertionindex]);
                                    assertTrue(next.getKey() == rand);
                                    Long result = finalStore.get(rand);
                                    assertTrue(result == rand);
                                } else {
                                    int nextIndex = ~insertionindex;
                                    while (deleted.get(nextIndex) && nextIndex < ints.length)
                                        nextIndex++;
                                    if (nextIndex < ints.length) {
                                        if (insertionindex != -1)
                                            assertTrue(ints[(~insertionindex) - 1] < rand);
                                        assertTrue(ints[nextIndex] + " != " + next.getKey(),
                                                ints[nextIndex] == next.getKey());

                                    }
                                    Long result = finalStore.get(rand);
                                    assertTrue(result == null);
                                }
                            }
                        }
                    }
                } catch (IOException e) {
                    throw new RuntimeException(e);
                } finally {
                    done.decrementAndGet();
                }
            }
        }).start();
    }
    while (done.get() > 0) {
        Thread.yield();
    }
    store.close();
}

From source file:edu.udo.scaffoldhunter.model.db.StringProperty.java

/**
 * Returns a new {@link BitSet} of the BitFingerprint
 * /*  www  . j  a v  a 2s  .co m*/
 * @return the fingerprint ({@link BitSet})
 */
public BitSet getBitFingerprintBitSet() {
    checkBitFingerprint();

    if (bitsCache != null) {
        return (BitSet) bitsCache.clone();
    }

    BitSet bits = new BitSet();
    byte[] bitFingerprint;
    bitFingerprint = Base64.decodeBase64(value);

    short length = bitFingerprintToLength(bitFingerprint);

    for (int i = 0; i < length; i++) {
        if ((bitFingerprint[i / sizeofbyte + lengthbytes] & (1 << (i % sizeofbyte))) > 0) {
            bits.set(i);
        }
    }

    bitsCache = (BitSet) bits.clone();
    lengthCache = length;
    return bits;
}

From source file:mastodon.algorithms.MHBisectionAlgorithm.java

protected void tryPruning() {
    //choose the number of species in list to perturb based on a Poisson distributions with rate equal to variable "mean" above
    int numberToSet = 0;
    int numberToClear = 0;

    while (numberToSet < 1 || numberToSet > currPrunedSpeciesCount) {
        numberToSet = pd.sample() + 1;/* w  w  w.  jav  a 2s.c  om*/
    }

    if (numberToSet > (bts.getTaxaCount() - currPrunedSpeciesCount)) {
        numberToSet = bts.getTaxaCount() - currPrunedSpeciesCount;
    }

    numberToClear = numberToSet;

    BitSet bitsToSet = new BitSet();
    BitSet bitsToClear = new BitSet();

    for (int e = 0; e < numberToSet; e++) {
        int choice = 0;
        while (true) {
            choice = (int) (Random.nextDouble() * bts.getTaxaCount());
            if (!currPruning.get(choice) && !bitsToSet.get(choice)) {
                break;
            }
        }
        bitsToSet.set(choice);
    }

    for (int e = 0; e < numberToClear; e++) {
        int choice = 0;
        while (true) {
            choice = (int) (Random.nextDouble() * bts.getTaxaCount());
            if (currPruning.get(choice) && !bitsToClear.get(choice)) {
                break;
            }
        }
        bitsToClear.set(choice);
    }

    currPruning.or(bitsToSet);
    currPruning.xor(bitsToClear);

    currScore = bts.pruneFast(currPruning);
    bts.unPrune();

}

From source file:com.asakusafw.runtime.io.csv.CsvEmitter.java

private BitSet buildQuoteMask(int[] indices) {
    if (indices.length == 0) {
        return null;
    }//ww w  . ja  v a2 s . c o  m
    BitSet results = new BitSet();
    IntStream.of(indices).forEach(results::set);
    return results;
}

From source file:hivemall.ftvec.ranking.PopulateNotInUDTF.java

@Override
public void process(Object[] args) throws HiveException {
    Object arg0 = args[0];/*  w ww .  j  a  va  2  s  .  c o  m*/
    if (arg0 == null || listOI.getListLength(arg0) == 0) {
        populateAll();
        return;
    }

    final BitSet bits;
    if (bitsetInput) {
        long[] longs = HiveUtils.asLongArray(arg0, listOI, listElemOI);
        bits = BitSet.valueOf(longs);
    } else {
        if (_bitset == null) {
            bits = new BitSet();
            this._bitset = bits;
        } else {
            bits = _bitset;
            bits.clear();
        }
        HiveUtils.setBits(arg0, listOI, listElemOI, bits);
    }

    populateItems(bits);
}