Package 

Class AtomicFastArray64

  • All Implemented Interfaces:
    io.github.millibyte1.array64.Array64 , io.github.millibyte1.array64.atomic.AtomicArray64 , kotlin.collections.Iterable

    
    public final class AtomicFastArray64<E extends Object>
    extends FastArray64<E> implements AtomicArray64<E>
                        

    An extension of the FastArray64 class supporting atomic operations such as compareAndSet. Loosely based off the Jetbrains JDK implementation of AtomicReferenceArray.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private final Long size
    • Method Summary

      Modifier and Type Method Description
      Long size() The number of elements in this array.
      E get(Long index) Returns the element at the given index.
      Unit set(Long index, E value) Sets the element at the given index to the given value.
      E getAndSet(Long index, E new) Sets the element at position index to the given new value and returns the old value.
      E getAndSet(Long index, Function1<E, E> transform) Sets the element at position index to the value resulting from applying the given transform to the old value.
      E setAndGet(Long index, Function1<E, E> transform) Sets the element at position index to the resulting value from applying the given transform to the old value.
      Boolean compareAndSet(Long index, E new, E expected) Sets the element at position index to the given new value if the current value matches expected.
      Boolean compareAndSet(Long index, E new, Function2<E, E, Boolean> predicate) Sets the element at position index to the given new value if the provided predicate returns true when applied to the old and new values.
      Unit lazySet(Long index, E value) Eventually sets the element at the given index to the given value.
      AtomicArray64Iterator<E> iterator(Long index) Returns an iterator to the element at the given index.
      AtomicArray64Iterator<E> iterator() Returns an iterator to the first element in this array.
      • Methods inherited from class io.github.millibyte1.array64.atomic.AtomicFastArray64

        copy, equals, hashCode
      • Methods inherited from class io.github.millibyte1.array64.Array64

        forEach, spliterator
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • size

         Long size()

        The number of elements in this array.

      • get

         E get(Long index)

        Returns the element at the given index. This method can be called using the index operator.

        Parameters:
        index - the index of the desired element
      • set

         Unit set(Long index, E value)

        Sets the element at the given index to the given value. This method can be called using the index operator.

        Parameters:
        index - the index of the element to set
        value - the value to set the element to
      • getAndSet

         E getAndSet(Long index, E new)

        Sets the element at position index to the given new value and returns the old value. Atomic.

        Parameters:
        index - the index of the element to set
        new - the value to set the element to
      • getAndSet

         E getAndSet(Long index, Function1<E, E> transform)

        Sets the element at position index to the value resulting from applying the given transform to the old value. Atomic.

        Parameters:
        index - the index of the element to set
        transform - the pure (side effect-free) transform function to apply to the old value
      • setAndGet

         E setAndGet(Long index, Function1<E, E> transform)

        Sets the element at position index to the resulting value from applying the given transform to the old value. Atomic.

        Parameters:
        index - the index of the element to set
        transform - the pure (side effect-free) transform function to apply to the old value
      • compareAndSet

         Boolean compareAndSet(Long index, E new, E expected)

        Sets the element at position index to the given new value if the current value matches expected. Atomic.

        Parameters:
        index - the index of the element to try and set
        new - the value to set the element to
        expected - the expected value of the element
      • compareAndSet

         Boolean compareAndSet(Long index, E new, Function2<E, E, Boolean> predicate)

        Sets the element at position index to the given new value if the provided predicate returns true when applied to the old and new values.

        Parameters:
        index - the index of the element to try and set
        new - the value to set the element to
        predicate - the binary predicate to apply to the old and new values to decide whether to update
      • lazySet

         Unit lazySet(Long index, E value)

        Eventually sets the element at the given index to the given value. Depending on the implementation, may immediately perform a volatile write.

        Parameters:
        index - the index of the element to set
        value - the value to set the element to