List of utility methods to do BitSet
int | firstInvalidOctet(CharSequence cs, BitSet bits) first Invalid Octet for (int i = 0; i < cs.length(); i++) { char c = cs.charAt(i); if (!bits.get(c)) { return i; return -1; |
String | formatBitset(BitSet bitset, int width) format Bitset StringBuilder str = new StringBuilder(); for (int i = (width - 1); i >= 0; i--) { if (bitset.get(i)) { str.append("1"); } else { str.append("0"); return str.toString(); |
BitSet | generateBitSetBySize(int size, boolean initValue) generate a BitSet by size BitSet bitSet = new BitSet(size); if (initValue) { bitSet.set(0, size); return bitSet; |
int | getBiggerRang(BitSet bitSet) Retrun bigger rang from bit set. for (int i = bitSet.size() - 1; i >= 0; i--) { if (bitSet.get(i)) return i; return 0; |
BitSet | getBitSet() get Bit Set return new BitSet(); |
BitSet | getBitSetFromBooleanArray(boolean[] buf) Convert a boolean[] into an instance of our value class. BitSet set = new BitSet(); for (int i = 0; i < buf.length; i++) { if (buf[i]) { set.set(i); return set; |
String | getLemma(String[] tokens, BitSet bits, String delimiter) get Lemma StringBuffer buf = new StringBuffer(); for (int i = 0; i < tokens.length; i++) { if (i != 0 && !bits.get(i - 1)) { buf.append(delimiter); buf.append(tokens[i]); return buf.toString(); ... |
int[] | getSetBitIndices(BitSet bitSet) Convert a bit representation of a set to its index representation 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; |
int | hammingDistance(BitSet bs1, BitSet bs2) hamming Distance BitSet ref = (BitSet) bs1.clone();
ref.and(bs2);
return (bs1.cardinality() - ref.cardinality());
|
boolean | hasAtLeastOneBitSet(BitSet bitSet, Iterable Returns true if at least one bit on a given position is set. for (Integer index : indexes) { if (bitSet.get(index)) { return true; return false; |