Here you can find the source of getSetBitIndices(BitSet bitSet)
Parameter | Description |
---|---|
bitSet | the bit set representations |
public static int[] getSetBitIndices(BitSet bitSet)
//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; } }