java.util.function.LongUnaryOperator Java Examples

The following examples show how to use java.util.function.LongUnaryOperator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LongStream.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns an infinite sequential ordered {@code LongStream} produced by iterative
 * application of a function {@code f} to an initial element {@code seed},
 * producing a {@code Stream} consisting of {@code seed}, {@code f(seed)},
 * {@code f(f(seed))}, etc.
 *
 * <p>The first element (position {@code 0}) in the {@code LongStream} will
 * be the provided {@code seed}.  For {@code n > 0}, the element at position
 * {@code n}, will be the result of applying the function {@code f} to the
 * element at position {@code n - 1}.
 *
 * @param seed the initial element
 * @param f a function to be applied to to the previous element to produce
 *          a new element
 * @return a new sequential {@code LongStream}
 */
public static LongStream iterate(final long seed, final LongUnaryOperator f) {
    Objects.requireNonNull(f);
    final PrimitiveIterator.OfLong iterator = new PrimitiveIterator.OfLong() {
        long t = seed;

        @Override
        public boolean hasNext() {
            return true;
        }

        @Override
        public long nextLong() {
            long v = t;
            t = f.applyAsLong(t);
            return v;
        }
    };
    return StreamSupport.longStream(Spliterators.spliteratorUnknownSize(
            iterator,
            Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL), false);
}
 
Example #2
Source File: LongPipeline.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public final LongStream map(LongUnaryOperator mapper) {
    Objects.requireNonNull(mapper);
    return new StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                 StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedLong<Long>(sink) {
                @Override
                public void accept(long t) {
                    downstream.accept(mapper.applyAsLong(t));
                }
            };
        }
    };
}
 
Example #3
Source File: LongStream.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns an infinite sequential ordered {@code LongStream} produced by iterative
 * application of a function {@code f} to an initial element {@code seed},
 * producing a {@code Stream} consisting of {@code seed}, {@code f(seed)},
 * {@code f(f(seed))}, etc.
 *
 * <p>The first element (position {@code 0}) in the {@code LongStream} will
 * be the provided {@code seed}.  For {@code n > 0}, the element at position
 * {@code n}, will be the result of applying the function {@code f} to the
 * element at position {@code n - 1}.
 *
 * @param seed the initial element
 * @param f a function to be applied to the previous element to produce
 *          a new element
 * @return a new sequential {@code LongStream}
 */
public static LongStream iterate(final long seed, final LongUnaryOperator f) {
    Objects.requireNonNull(f);
    final PrimitiveIterator.OfLong iterator = new PrimitiveIterator.OfLong() {
        long t = seed;

        @Override
        public boolean hasNext() {
            return true;
        }

        @Override
        public long nextLong() {
            long v = t;
            t = f.applyAsLong(t);
            return v;
        }
    };
    return StreamSupport.longStream(Spliterators.spliteratorUnknownSize(
            iterator,
            Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL), false);
}
 
Example #4
Source File: LongPipeline.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
@Override
public final LongStream map(LongUnaryOperator mapper) {
    Objects.requireNonNull(mapper);
    return new StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                 StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedLong<Long>(sink) {
                @Override
                public void accept(long t) {
                    downstream.accept(mapper.applyAsLong(t));
                }
            };
        }
    };
}
 
Example #5
Source File: LongPipeline.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public final LongStream map(LongUnaryOperator mapper) {
    Objects.requireNonNull(mapper);
    return new StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                 StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedLong<Long>(sink) {
                @Override
                public void accept(long t) {
                    downstream.accept(mapper.applyAsLong(t));
                }
            };
        }
    };
}
 
Example #6
Source File: LongPipeline.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public final LongStream map(LongUnaryOperator mapper) {
    Objects.requireNonNull(mapper);
    return new StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                 StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedLong<Long>(sink) {
                @Override
                public void accept(long t) {
                    downstream.accept(mapper.applyAsLong(t));
                }
            };
        }
    };
}
 
Example #7
Source File: LongStream.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns an infinite sequential ordered {@code LongStream} produced by iterative
 * application of a function {@code f} to an initial element {@code seed},
 * producing a {@code Stream} consisting of {@code seed}, {@code f(seed)},
 * {@code f(f(seed))}, etc.
 *
 * <p>The first element (position {@code 0}) in the {@code LongStream} will
 * be the provided {@code seed}.  For {@code n > 0}, the element at position
 * {@code n}, will be the result of applying the function {@code f} to the
 * element at position {@code n - 1}.
 *
 * @param seed the initial element
 * @param f a function to be applied to to the previous element to produce
 *          a new element
 * @return a new sequential {@code LongStream}
 */
public static LongStream iterate(final long seed, final LongUnaryOperator f) {
    Objects.requireNonNull(f);
    final PrimitiveIterator.OfLong iterator = new PrimitiveIterator.OfLong() {
        long t = seed;

        @Override
        public boolean hasNext() {
            return true;
        }

        @Override
        public long nextLong() {
            long v = t;
            t = f.applyAsLong(t);
            return v;
        }
    };
    return StreamSupport.longStream(Spliterators.spliteratorUnknownSize(
            iterator,
            Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL), false);
}
 
Example #8
Source File: LongPipeline.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public final LongStream map(LongUnaryOperator mapper) {
    Objects.requireNonNull(mapper);
    return new StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                 StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedLong<Long>(sink) {
                @Override
                public void accept(long t) {
                    downstream.accept(mapper.applyAsLong(t));
                }
            };
        }
    };
}
 
Example #9
Source File: LongStream.java    From desugar_jdk_libs with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns an infinite sequential ordered {@code LongStream} produced by iterative
 * application of a function {@code f} to an initial element {@code seed},
 * producing a {@code Stream} consisting of {@code seed}, {@code f(seed)},
 * {@code f(f(seed))}, etc.
 *
 * <p>The first element (position {@code 0}) in the {@code LongStream} will
 * be the provided {@code seed}.  For {@code n > 0}, the element at position
 * {@code n}, will be the result of applying the function {@code f} to the
 * element at position {@code n - 1}.
 *
 * @param seed the initial element
 * @param f a function to be applied to to the previous element to produce
 *          a new element
 * @return a new sequential {@code LongStream}
 */
public static LongStream iterate(final long seed, final LongUnaryOperator f) {
    Objects.requireNonNull(f);
    final PrimitiveIterator.OfLong iterator = new PrimitiveIterator.OfLong() {
        long t = seed;

        @Override
        public boolean hasNext() {
            return true;
        }

        @Override
        public long nextLong() {
            long v = t;
            t = f.applyAsLong(t);
            return v;
        }
    };
    return StreamSupport.longStream(Spliterators.spliteratorUnknownSize(
            iterator,
            Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL), false);
}
 
Example #10
Source File: LongStream.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns an infinite sequential ordered {@code LongStream} produced by iterative
 * application of a function {@code f} to an initial element {@code seed},
 * producing a {@code Stream} consisting of {@code seed}, {@code f(seed)},
 * {@code f(f(seed))}, etc.
 *
 * <p>The first element (position {@code 0}) in the {@code LongStream} will
 * be the provided {@code seed}.  For {@code n > 0}, the element at position
 * {@code n}, will be the result of applying the function {@code f} to the
 * element at position {@code n - 1}.
 *
 * @param seed the initial element
 * @param f a function to be applied to the previous element to produce
 *          a new element
 * @return a new sequential {@code LongStream}
 */
public static LongStream iterate(final long seed, final LongUnaryOperator f) {
    Objects.requireNonNull(f);
    final PrimitiveIterator.OfLong iterator = new PrimitiveIterator.OfLong() {
        long t = seed;

        @Override
        public boolean hasNext() {
            return true;
        }

        @Override
        public long nextLong() {
            long v = t;
            t = f.applyAsLong(t);
            return v;
        }
    };
    return StreamSupport.longStream(Spliterators.spliteratorUnknownSize(
            iterator,
            Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL), false);
}
 
Example #11
Source File: LongStream.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Returns an infinite sequential ordered {@code LongStream} produced by iterative
 * application of a function {@code f} to an initial element {@code seed},
 * producing a {@code Stream} consisting of {@code seed}, {@code f(seed)},
 * {@code f(f(seed))}, etc.
 *
 * <p>The first element (position {@code 0}) in the {@code LongStream} will
 * be the provided {@code seed}.  For {@code n > 0}, the element at position
 * {@code n}, will be the result of applying the function {@code f} to the
 * element at position {@code n - 1}.
 *
 * @param seed the initial element
 * @param f a function to be applied to to the previous element to produce
 *          a new element
 * @return a new sequential {@code LongStream}
 */
public static LongStream iterate(final long seed, final LongUnaryOperator f) {
    Objects.requireNonNull(f);
    final PrimitiveIterator.OfLong iterator = new PrimitiveIterator.OfLong() {
        long t = seed;

        @Override
        public boolean hasNext() {
            return true;
        }

        @Override
        public long nextLong() {
            long v = t;
            t = f.applyAsLong(t);
            return v;
        }
    };
    return StreamSupport.longStream(Spliterators.spliteratorUnknownSize(
            iterator,
            Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL), false);
}
 
Example #12
Source File: LongStream.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Returns an infinite sequential ordered {@code LongStream} produced by iterative
 * application of a function {@code f} to an initial element {@code seed},
 * producing a {@code Stream} consisting of {@code seed}, {@code f(seed)},
 * {@code f(f(seed))}, etc.
 *
 * <p>The first element (position {@code 0}) in the {@code LongStream} will
 * be the provided {@code seed}.  For {@code n > 0}, the element at position
 * {@code n}, will be the result of applying the function {@code f} to the
 * element at position {@code n - 1}.
 *
 * <p>The action of applying {@code f} for one element
 * <a href="../concurrent/package-summary.html#MemoryVisibility"><i>happens-before</i></a>
 * the action of applying {@code f} for subsequent elements.  For any given
 * element the action may be performed in whatever thread the library
 * chooses.
 *
 * @param seed the initial element
 * @param f a function to be applied to the previous element to produce
 *          a new element
 * @return a new sequential {@code LongStream}
 */
public static LongStream iterate(final long seed, final LongUnaryOperator f) {
    Objects.requireNonNull(f);
    Spliterator.OfLong spliterator = new Spliterators.AbstractLongSpliterator(Long.MAX_VALUE,
           Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL) {
        long prev;
        boolean started;

        @Override
        public boolean tryAdvance(LongConsumer action) {
            Objects.requireNonNull(action);
            long t;
            if (started)
                t = f.applyAsLong(prev);
            else {
                t = seed;
                started = true;
            }
            action.accept(prev = t);
            return true;
        }
    };
    return StreamSupport.longStream(spliterator, false);
}
 
Example #13
Source File: LongPipeline.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Override
public final LongStream map(LongUnaryOperator mapper) {
    Objects.requireNonNull(mapper);
    return new StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                 StreamOpFlag.NOT_SORTED | StreamOpFlag.NOT_DISTINCT) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedLong<Long>(sink) {
                @Override
                public void accept(long t) {
                    downstream.accept(mapper.applyAsLong(t));
                }
            };
        }
    };
}
 
Example #14
Source File: WheelTimer.java    From oxygen with Apache License 2.0 5 votes vote down vote up
/**
 * cron任务
 *
 * @param command 任务
 * @param cron 表达式
 * @return ScheduledFuture
 */
public ScheduledFuture<Void> scheduleOnCron(Runnable command, String cron) {
  start();
  LongUnaryOperator operator = new CronExpression(cron).operator();
  long deadline = operator.applyAsLong(0);
  if (deadline == Long.MIN_VALUE) {
    throw Exceptions.fail("cron doesn't have any match in the future");
  }
  PeriodTask task = new PeriodTask(deadline, command, operator, this);
  addTaskInLock(task);
  return task;
}
 
Example #15
Source File: RLPDecodingHelpers.java    From besu with Apache License 2.0 5 votes vote down vote up
/** The size of the item payload for a "long" item, given the length in bytes of the said size. */
private static int readLongSize(
    final LongUnaryOperator byteGetter,
    final long sizeOfRlpEncodedByteString,
    final long item,
    final int sizeLength) {
  // We will read sizeLength bytes from item + 1. There must be enough bytes for this or the input
  // is corrupted.
  if (sizeOfRlpEncodedByteString - (item + 1) < sizeLength) {
    throw new CorruptedRLPInputException(
        String.format(
            "Invalid RLP item: value of size %d has not enough bytes to read the %d "
                + "bytes payload size",
            sizeOfRlpEncodedByteString, sizeLength));
  }

  // That size (which is at least 1 byte by construction) shouldn't have leading zeros.
  if (byteGetter.applyAsLong(item + 1) == 0) {
    throw new MalformedRLPInputException("Malformed RLP item: size of payload has leading zeros");
  }

  final int res = RLPDecodingHelpers.extractSizeFromLongItem(byteGetter, item + 1, sizeLength);

  // We should not have had the size written separately if it was less than 56 bytes long.
  if (res < 56) {
    throw new MalformedRLPInputException(
        String.format("Malformed RLP item: written as a long item, but size %d < 56 bytes", res));
  }

  return res;
}
 
Example #16
Source File: RLPDecodingHelpers.java    From besu with Apache License 2.0 5 votes vote down vote up
/** Read from the provided offset a size of the provided length, assuming this is enough bytes. */
private static int extractSizeFromLongItem(
    final LongUnaryOperator getter, final long offset, final int sizeLength) {
  if (sizeLength > 4) {
    throw new RLPException(
        "RLP item at offset "
            + offset
            + " with size value consuming "
            + sizeLength
            + " bytes exceeds max supported size of "
            + Integer.MAX_VALUE);
  }

  long res = 0;
  int shift = 0;
  for (int i = 0; i < sizeLength; i++) {
    res |= (getter.applyAsLong(offset + (sizeLength - 1) - i) & 0xFF) << shift;
    shift += 8;
  }
  try {
    return Math.toIntExact(res);
  } catch (final ArithmeticException e) {
    throw new RLPException(
        "RLP item at offset "
            + offset
            + " with size value consuming "
            + sizeLength
            + " bytes exceeds max supported size of "
            + Integer.MAX_VALUE,
        e);
  }
}
 
Example #17
Source File: PartitionTransforms.java    From presto with Apache License 2.0 5 votes vote down vote up
private static Block extractTimestampWithTimeZone(Block block, LongUnaryOperator function)
{
    BlockBuilder builder = INTEGER.createFixedSizeBlockBuilder(block.getPositionCount());
    for (int position = 0; position < block.getPositionCount(); position++) {
        if (block.isNull(position)) {
            builder.appendNull();
            continue;
        }
        long value = unpackMillisUtc(TIMESTAMP_WITH_TIME_ZONE.getLong(block, position));
        value = function.applyAsLong(value);
        INTEGER.writeLong(builder, value);
    }
    return builder.build();
}
 
Example #18
Source File: PartitionTransforms.java    From presto with Apache License 2.0 5 votes vote down vote up
private static Block extractDate(Block block, LongUnaryOperator function)
{
    BlockBuilder builder = INTEGER.createFixedSizeBlockBuilder(block.getPositionCount());
    for (int position = 0; position < block.getPositionCount(); position++) {
        if (block.isNull(position)) {
            builder.appendNull();
            continue;
        }
        long value = DATE.getLong(block, position);
        value = function.applyAsLong(value);
        INTEGER.writeLong(builder, value);
    }
    return builder.build();
}
 
Example #19
Source File: RLPDecodingHelpers.java    From besu with Apache License 2.0 5 votes vote down vote up
static RLPElementMetadata rlpElementMetadata(
    final LongUnaryOperator byteGetter, final long size, final long elementStart) {
  final int prefix = Math.toIntExact(byteGetter.applyAsLong(elementStart)) & 0xFF;
  final Kind kind = Kind.of(prefix);
  long payloadStart = 0;
  int payloadSize = 0;

  switch (kind) {
    case BYTE_ELEMENT:
      payloadStart = elementStart;
      payloadSize = 1;
      break;
    case SHORT_ELEMENT:
      payloadStart = elementStart + 1;
      payloadSize = prefix - 0x80;
      break;
    case LONG_ELEMENT:
      final int sizeLengthElt = prefix - 0xb7;
      payloadStart = elementStart + 1 + sizeLengthElt;
      payloadSize = readLongSize(byteGetter, size, elementStart, sizeLengthElt);
      break;
    case SHORT_LIST:
      payloadStart = elementStart + 1;
      payloadSize = prefix - 0xc0;
      break;
    case LONG_LIST:
      final int sizeLengthList = prefix - 0xf7;
      payloadStart = elementStart + 1 + sizeLengthList;
      payloadSize = readLongSize(byteGetter, size, elementStart, sizeLengthList);
      break;
  }

  return new RLPElementMetadata(kind, elementStart, payloadStart, payloadSize);
}
 
Example #20
Source File: TestRaftLogIndex.java    From incubator-ratis with Apache License 2.0 5 votes vote down vote up
static void assertUpdate(RaftLogIndex index, BiFunction<RaftLogIndex, LongUnaryOperator, Boolean> update,
    long oldValue, LongUnaryOperator op, boolean expectUpdate) {
  Assert.assertEquals(oldValue, index.get());
  final boolean updated = update.apply(index, op);
  Assert.assertEquals(expectUpdate, updated);
  Assert.assertEquals(expectUpdate? op.applyAsLong(oldValue): oldValue, index.get());
}
 
Example #21
Source File: SampleOperator.java    From rheem with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance given user-defined sample size and seed methods.
 */
public SampleOperator(IntUnaryOperator sampleSizeFunction, DataSetType<Type> type, Methods sampleMethod, LongUnaryOperator seedFunction) {
    super(type, type, true);
    this.sampleSizeFunction = sampleSizeFunction;
    this.sampleMethod = sampleMethod;
    this.seedFunction = seedFunction;
}
 
Example #22
Source File: SparkRandomPartitionSampleOperator.java    From rheem with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new instance.
 */
public SparkRandomPartitionSampleOperator(IntUnaryOperator sampleSizeFunction, DataSetType<Type> type, LongUnaryOperator seedFunction) {
    super(sampleSizeFunction, type, Methods.RANDOM, seedFunction);
}
 
Example #23
Source File: JavaReservoirSampleOperator.java    From rheem with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new instance.
 */
public JavaReservoirSampleOperator(IntUnaryOperator sampleSizeFunction, DataSetType<Type> type, LongUnaryOperator seed) {
    super(sampleSizeFunction, type, Methods.RESERVOIR, seed);
}
 
Example #24
Source File: FlinkSampleOperator.java    From rheem with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new instance.
 */
public FlinkSampleOperator(IntUnaryOperator sampleSizeFunction, DataSetType<Type> type, LongUnaryOperator seedFunction) {
    super(sampleSizeFunction, type, Methods.RANDOM, seedFunction);
}
 
Example #25
Source File: CronExpression.java    From oxygen with Apache License 2.0 4 votes vote down vote up
public LongUnaryOperator operator() {
  return new CronOperator(this);
}
 
Example #26
Source File: DefaultMethodStreams.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public LongStream map(LongUnaryOperator mapper) {
    return s.map(mapper);
}
 
Example #27
Source File: PeriodTask.java    From oxygen with Apache License 2.0 4 votes vote down vote up
PeriodTask(long deadline, Runnable runnable, LongUnaryOperator operator, WheelTimer timer) {
  super(deadline, runnable);
  this.operator = operator;
  this.timer = timer;
}
 
Example #28
Source File: RoleData.java    From catnip with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Nonnull
public RoleData updatePermissions(@Nonnull final LongUnaryOperator updater) {
    return permissions(updater.applyAsLong(permissions == null ? 0 : permissions));
}
 
Example #29
Source File: AtomicLongArray.java    From jdk1.8-source-analysis with Apache License 2.0 3 votes vote down vote up
/**
 * Atomically updates the element at index {@code i} with the results
 * of applying the given function, returning the updated value. The
 * function should be side-effect-free, since it may be re-applied
 * when attempted updates fail due to contention among threads.
 *
 * @param i the index
 * @param updateFunction a side-effect-free function
 * @return the updated value
 * @since 1.8
 */
public final long updateAndGet(int i, LongUnaryOperator updateFunction) {
    long offset = checkedByteOffset(i);
    long prev, next;
    do {
        prev = getRaw(offset);
        next = updateFunction.applyAsLong(prev);
    } while (!compareAndSetRaw(offset, prev, next));
    return next;
}
 
Example #30
Source File: AtomicLongArray.java    From Bytecoder with Apache License 2.0 3 votes vote down vote up
/**
 * Atomically updates (with memory effects as specified by {@link
 * VarHandle#compareAndSet}) the element at index {@code i} with
 * the results of applying the given function, returning the
 * updated value. The function should be side-effect-free, since it
 * may be re-applied when attempted updates fail due to contention
 * among threads.
 *
 * @param i the index
 * @param updateFunction a side-effect-free function
 * @return the updated value
 * @since 1.8
 */
public final long updateAndGet(int i, LongUnaryOperator updateFunction) {
    long prev = get(i), next = 0L;
    for (boolean haveNext = false;;) {
        if (!haveNext)
            next = updateFunction.applyAsLong(prev);
        if (weakCompareAndSetVolatile(i, prev, next))
            return next;
        haveNext = (prev == (prev = get(i)));
    }
}