Exemple #1
0
 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));
   }
 }
Exemple #2
0
 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));
     }
   }
 }
Exemple #3
0
 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)));
     }
   }
 }
Exemple #4
0
 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;
 }
Exemple #5
0
 @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;
 }
Exemple #6
0
 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;
 }
Exemple #7
0
 final int size() {
   return 64 - Long.bitCount(bitSet);
 }
Exemple #8
0
 /**
  * @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;
 }