Java BitSet getSetBitIndices(BitSet bitSet)

Here you can find the source of getSetBitIndices(BitSet bitSet)

Description

Convert a bit representation of a set to its index representation

License

Open Source License

Parameter

Parameter Description
bitSet the bit set representations

Return

the index array representation

Declaration

public static int[] getSetBitIndices(BitSet bitSet) 

Method Source Code

//package com.java2s;
/*//from  w w w.  java2 s .c o m
 * Copyright (c) 2010 The Jackson Laboratory
 * 
 * This is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this software.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.BitSet;

public class Main {
    /**
     * Convert a bit representation of a set to its index representation
     * @param bitSet
     *          the bit set representations
     * @return
     *          the index array representation
     */
    public static int[] getSetBitIndices(BitSet bitSet) {
        int[] setBitIndices = new int[bitSet.cardinality()];
        int currSetBitIndex = 0;
        int currBitIndex = 0;
        while (currSetBitIndex < setBitIndices.length) {
            if (bitSet.get(currBitIndex)) {
                setBitIndices[currSetBitIndex] = currBitIndex;
                currSetBitIndex++;
            }

            currBitIndex++;
        }

        return setBitIndices;
    }
}

Related

  1. generateBitSetBySize(int size, boolean initValue)
  2. getBiggerRang(BitSet bitSet)
  3. getBitSet()
  4. getBitSetFromBooleanArray(boolean[] buf)
  5. getLemma(String[] tokens, BitSet bits, String delimiter)
  6. hammingDistance(BitSet bs1, BitSet bs2)
  7. hasAtLeastOneBitSet(BitSet bitSet, Iterable indexes)
  8. hex2BitSet(byte[] b, int offset, int maxBits)
  9. hexToBits(String s, BitSet ba, int length)