final void forEachValue(Consumer<? super V> action) { for (long a, tail, allocations = (a = ~bitSet) << (tail = Long.numberOfLeadingZeros(a)), allocIndex = 64 - tail; allocations != 0; allocations <<= 1, allocIndex--) { if (allocations < 0) action.accept(this.<V>readValue(allocIndex)); } }
final void writeAllEntries(ObjectOutputStream s) throws IOException { for (long a, tail, allocations = (a = ~bitSet) << (tail = Long.numberOfLeadingZeros(a)), allocIndex = 64 - tail; allocations != 0; allocations <<= 1, allocIndex--) { if (allocations < 0) { s.writeObject(readKey(allocIndex)); s.writeObject(readValue(allocIndex)); } } }
final void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) { for (long a, tail, allocations = (a = ~bitSet) << (tail = Long.numberOfLeadingZeros(a)), allocIndex = 64 - tail; allocations != 0; allocations <<= 1, allocIndex--) { if (allocations < 0) { writeValue( allocIndex, function.apply(this.<K>readKey(allocIndex), this.<V>readValue(allocIndex))); } } }
final boolean forEachWhile(BiPredicate<? super K, ? super V> predicate) { for (long a, tail, allocations = (a = ~bitSet) << (tail = Long.numberOfLeadingZeros(a)), allocIndex = 64 - tail; allocations != 0; allocations <<= 1, allocIndex--) { if (allocations < 0 && !predicate.test(this.<K>readKey(allocIndex), this.<V>readValue(allocIndex))) { return false; } } return true; }
@Override public final int hashCode() { int h = 0; for (long a, tail, allocations = (a = ~bitSet) << (tail = Long.numberOfLeadingZeros(a)), allocIndex = 64 - tail; allocations != 0; allocations <<= 1, allocIndex--) { if (allocations < 0) { h += Objects.hashCode(readKey(allocIndex)) ^ Objects.hashCode(readValue(allocIndex)); } } return h; }
final boolean containsValue(SmoothieMap<K, V> map, V value) { V v; for (long a, tail, allocations = (a = ~bitSet) << (tail = Long.numberOfLeadingZeros(a)), allocIndex = 64 - tail; allocations != 0; allocations <<= 1, allocIndex--) { if (allocations < 0) { if (((v = readValue(allocIndex)) == value || (value != null && map.valuesEqual(value, v)))) { return true; } } } return false; }
final int size() { return 64 - Long.bitCount(bitSet); }
/** * @return 1-indexed alloc index, to allow {@code slot != 0} conditions, i. e. allocIndex = 0 * means empty hash table slot */ final long alloc() { long bitSet = this.bitSet; this.bitSet = (bitSet - 1) & bitSet; return Long.numberOfTrailingZeros(bitSet) + 1; }