private List<Long> bits(long x) { List<Long> r = Lists.newArrayList(); long l = x; while (l != 0) { long bit = Long.lowestOneBit(l); r.add(bit); l ^= bit; } return r; }
public void free(final ByteBuffer bb) { long posn = Long.lowestOneBit(~availableBits & mask); if (posn != 0L) { int bit = Long.numberOfTrailingZeros(posn); // mark available availableBits |= posn; cache[bit] = bb; } else { // full parent.free(bb); } }
public ByteBuffer allocate() { long posn = Long.lowestOneBit(availableBits); if (posn != 0L) { int bit = Long.numberOfTrailingZeros(posn); availableBits &= ~posn; try { return cache[bit]; } finally { cache[bit] = null; } } else { // empty return parent.allocate(); } }
public void destroy() { final ByteBuffer[] cache = this.cache; final Cache parent = this.parent; long bits = ~availableBits & mask; try { while (bits != 0L) { long posn = Long.lowestOneBit(bits); int bit = Long.numberOfTrailingZeros(posn); parent.free(cache[bit]); bits &= ~posn; cache[bit] = null; } } finally { // should be 0, but maintain a consistent state in case a free failed availableBits = bits; } }
/** * Get the canonical action string representation for the given action set, appending it to the given string builder. * * @param type the action {@code enum} type class * @param set the action set * @param b the string builder * @param <E> the action type */ public static <E extends Enum<E>> void getCanonicalActionString(Class<E> type, long set, StringBuilder b) { if (set == 0) return; @SuppressWarnings("unchecked") final E[] constants = (E[]) storedInfo.get(type).constants; long bit = Long.lowestOneBit(set); E e = constants[Long.numberOfTrailingZeros(bit)]; b.append(e.toString()); set &= ~bit; while (set != 0) { bit = Long.lowestOneBit(set); e = constants[Long.numberOfTrailingZeros(bit)]; b.append(',').append(e.toString()); set &= ~bit; } } }
private static int[] createSorted16BitInts(int howMany) { long[] bitset = bits.get(); Arrays.fill(bitset, 0L); int consumed = 0; while (consumed < howMany) { int value = ThreadLocalRandom.current().nextInt(1 << 16); long bit = (1L << value); consumed += 1 - Long.bitCount(bitset[value >>> 6] & bit); bitset[value >>> 6] |= bit; } int[] keys = new int[howMany]; int prefix = 0; int k = 0; for (int i = bitset.length - 1; i >= 0; --i) { long word = bitset[i]; while (word != 0) { keys[k++] = prefix + Long.numberOfTrailingZeros(word); word ^= Long.lowestOneBit(word); } prefix += 64; } return keys; }
public Permission nextElement() { final long bits = this.bits; if (bits == 0) throw new NoSuchElementException(); if (Long.bitCount(bits) == getNameEnumeration().size()) { this.bits = 0; return ((AbstractNamedPermission<?>) getSourcePermission()).withName("*"); } long bit = Long.lowestOneBit(bits); this.bits = bits & ~bit; return permissionFor(Long.numberOfTrailingZeros(bit)); }
public void flush() { final ByteBuffer[] cache = this.cache; final Cache parent = this.parent; long bits = ~availableBits & mask; try { while (bits != 0L) { long posn = Long.lowestOneBit(bits); int bit = Long.numberOfTrailingZeros(posn); flushBuffer(cache[bit]); bits &= ~posn; cache[bit] = null; } } finally { // should be 0, but maintain a consistent state in case a free failed availableBits = bits; } parent.flush(); } }
public int findSmallerSibling(long valueBits, long valueMask) { if ((valueBits | valueMask) != valueMask) { throw new IllegalArgumentException("Dismatch " + Long.toBinaryString(valueBits) + " from " + Long.toBinaryString(valueMask)); } int n = Long.bitCount(valueMask); int k = Long.bitCount(valueBits); long[] bitMasks = new long[n]; long leftBits = valueMask; for (int i = 0; i < n; i++) { long lowestBit = Long.lowestOneBit(leftBits); bitMasks[i] = lowestBit; leftBits &= ~lowestBit; } return combination(valueBits, bitMasks, 0, 0L, k); }
if (nonJointNonHierarchy != 0) { return cuboidID | Long.lowestOneBit(nonJointNonHierarchy); } else {
public int findSmallerSibling(long valueBits, long valueMask) { if ((valueBits | valueMask) != valueMask) { throw new IllegalArgumentException("Dismatch " + Long.toBinaryString(valueBits) + " from " + Long.toBinaryString(valueMask)); } int n = Long.bitCount(valueMask); int k = Long.bitCount(valueBits); long[] bitMasks = new long[n]; long leftBits = valueMask; for (int i = 0; i < n; i++) { long lowestBit = Long.lowestOneBit(leftBits); bitMasks[i] = lowestBit; leftBits &= ~lowestBit; } return combination(valueBits, bitMasks, 0, 0L, k); }
protected int decompose(long[] buffer, long base) { int count = 0; while ( 0 != (base -= (buffer[count++] = Long.lowestOneBit(base)))); return count; }
protected int decompose(long[] buffer, long base) { int count = Long.bitCount(base); for (int i = 0; i < count; i++) { base -= (buffer[i] = Long.lowestOneBit(base)); } return count; }
public LongLong lowestOneBit() { long newLo = Long.lowestOneBit(lo); long newHi; if(newLo!=0) { newHi = 0; } else { newHi = Long.lowestOneBit(hi); } if(newHi==hi && newLo==lo) return this; return valueOf(newHi, newLo); }
public Writable next() { last = Long.lowestOneBit(i); if (0 == last) throw new NoSuchElementException(); i ^= last; // numberOfTrailingZeros rtn 64 if lsb set return t.get(Long.numberOfTrailingZeros(last) % 64); }
public static DOMNotificationRouter create(final int queueDepth, final long spinTime, final long parkTime, final TimeUnit unit) { Preconditions.checkArgument(Long.lowestOneBit(queueDepth) == Long.highestOneBit(queueDepth), "Queue depth %s is not power-of-two", queueDepth); final ExecutorService executor = Executors.newCachedThreadPool(); final WaitStrategy strategy = PhasedBackoffWaitStrategy.withLock(spinTime, parkTime, unit); return new DOMNotificationRouter(executor, queueDepth, strategy); }
public Permission nextElement() { final long bits = this.bits; if (bits == 0) throw new NoSuchElementException(); if (Long.bitCount(bits) == getNameEnumeration().size()) { this.bits = 0; return ((AbstractNamedPermission<?>) getSourcePermission()).withName("*"); } long bit = Long.lowestOneBit(bits); this.bits = bits & ~bit; return permissionFor(Long.numberOfTrailingZeros(bit)); }
public Permission nextElement() { final long bits = this.bits; if (bits == 0) throw new NoSuchElementException(); if (Long.bitCount(bits) == getNameEnumeration().size()) { this.bits = 0; return ((AbstractNamedPermission<?>) getSourcePermission()).withName("*"); } long bit = Long.lowestOneBit(bits); this.bits = bits & ~bit; return permissionFor(Long.numberOfTrailingZeros(bit)); }
public Permission nextElement() { final long bits = this.bits; if (bits == 0) throw new NoSuchElementException(); if (Long.bitCount(bits) == getNameEnumeration().size()) { this.bits = 0; return ((AbstractNamedPermission<?>) getSourcePermission()).withName("*"); } long bit = Long.lowestOneBit(bits); this.bits = bits & ~bit; return permissionFor(Long.numberOfTrailingZeros(bit)); }
@Override public void validate() { super.validate(); final long depth = getNotificationQueueDepth().getValue(); Preconditions.checkArgument(Long.lowestOneBit(depth) == Long.highestOneBit(depth), "Queue depth %s is not power-of-two", depth); }