List of utility methods to do BitSet
boolean | isSubset(BitSet bits1, BitSet bits2) True if all bits set in first bitset are also set in second. int index = -1; while (true) { if (0 > (index = bits1.nextSetBit(++index))) break; if (!bits2.get(index)) return false; return true; ... |
boolean | isSubset(BitSet subsetToTest, BitSet supersetToTest) Determine if the 1st argument is a subset of the 2nd. BitSet intersection = (BitSet) supersetToTest.clone();
intersection.and(subsetToTest);
return intersection.equals(subsetToTest);
|
boolean | isSubSet(BitSet x, BitSet y) very inefficient, but Java wonderful bitset has no subset op perhaps using bit iterator would be faster, I can't be bothered. y = (BitSet) y.clone();
y.and(x);
return y.equals(x);
|
long | longFrom(final BitSet bitSet) Creates an long out of a bitset return longFrom(bitSet, NBITS_LONG_REPRESENTATION);
|
BitSet | longToBitSet(long bits) long To Bit Set BitSet ret = new BitSet(); for (int count = 0;; count++) { long curBit = 1L << count; ret.set(count, (bits & curBit) != 0); if (curBit >= bits) break; return ret; ... |
BitSet | longToBitSet(long value) Convert a BitSet to its equivalent integer (long) value. BitSet bits = new BitSet(Long.SIZE); int index = 0; while (value != 0L) { long rem = value % 2L; if (rem != 0) { bits.set(index); ++index; ... |
BitSet | mapToBitSet(Map Parses a string representation of a BitSet into a BitSet7 object. String sbits = map.get(key); if (sbits == null) return null; else return stringToBitSet(sbits); |
int | max(BitSet bits) get the largest member of the set int max = 0; for (int value = bits.nextSetBit(0); value != -1; value = bits.nextSetBit(value + 1)) { max = value; return max; |
Iterable | members(BitSet set) iterable over all members return () -> new Iterator<Integer>() { private int i = set.nextSetBit(0); @Override public boolean hasNext() { return i != -1; @Override public Integer next() { ... |
int | nextClearBitModulo(int index, int poolSize, BitSet bitSet) Returns index of next clear (false) bit, starting from and including index. int indexToSet = bitSet.nextClearBit(index); if (indexToSet == poolSize && index != 0) { indexToSet = bitSet.nextClearBit(0); if (indexToSet == poolSize) { return -1; return indexToSet; ... |