List of utility methods to do BitSet
int | countLeadingSimilarBits(BitSet a, BitSet b) count Leading Similar Bits int result = 0; for (int i = 127; i >= 0 && (a.get(i) == b.get(i)); i--) { result++; return result; |
BitSet | createBitSetFromBinaryString(String bitsAsBinaryString) converts a string to a bitset counting all 1's as true and all other characters as false 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; |
BitSet | createSimpleBitSet(Set create Simple Bit Set BitSet retval = new BitSet(); for (int i : setBits) { retval.set(i); return retval; |
BitSet | decode(BitSet encoded, int encodedBitLength) decode int decodedBitLength = encodedBitLength - (int) (Math.log(encodedBitLength) / Math.log(2)) - 1; BitSet decoded = new BitSet(decodedBitLength); for (int i = encodedBitLength - 1, j = decodedBitLength - 1; i >= 0; --i) { if (Math.log(encodedBitLength - i) / Math.log(2) % 1 != 0) { decoded.set(j, encoded.get(i)); --j; return decoded; |
long | decodeIndex(final BitSet bs, final long rangePerDimension) decode Index long floor = 0; long ceiling = rangePerDimension; long mid = 0; for (int i = 0; i < bs.length(); i++) { mid = (floor + ceiling) / 2; if (bs.get(i)) { floor = mid; } else { ... |
BitSet | deleteBits(BitSet bs, BitSet bsDelete) this one slides deleted bits out of a pattern. if (bs == null || bsDelete == null) return bs; int ipt = bsDelete.nextSetBit(0); if (ipt < 0) return bs; int len = bs.length(); int lend = Math.min(len, bsDelete.length()); int i; ... |
void | dualNext(BitSet b) dual Next int index = b.nextClearBit(0);
b.set(index);
b.flip(0, index);
|
String | encode(BitSet allowedCharacters, String s, String charset) encode if (s == null) return null; final StringBuilder encoded = new StringBuilder(s.length() * 3); final char[] characters = s.toCharArray(); try { for (char c : characters) { if (allowedCharacters.get(c)) { encoded.append(c); ... |
BitSet | encode(BitSet origin, int originBitLength) encode int encodedBitLength = (int) (originBitLength + Math.log(originBitLength) / Math.log(2) + 1); BitSet encoded = new BitSet(encodedBitLength); for (int i = 1, j = originBitLength - 1; i <= encodedBitLength; ++i) { if (Math.log(i) / Math.log(2) % 1 == 0) { encoded.set(encodedBitLength - i, false); } else { encoded.set(encodedBitLength - i, origin.get(j)); --j; ... |
String | encode(String s, BitSet bs) encode StringBuilder buf = null; int len = s.length(); for (int i = 0; i < len; i++) { int ch = s.charAt(i); if (bs.get(ch)) { if (buf != null) buf.append((char) ch); } else { ... |