-
- All Implemented Interfaces:
-
io.github.millibyte1.array64.Array64
,io.github.millibyte1.array64.ByteArray64
,io.github.millibyte1.array64.atomic.AtomicArray64
,kotlin.collections.Iterable
public final class AtomicFastByteArray64 extends FastByteArray64 implements AtomicArray64<Byte>
An extension of the FastByteArray64 class supporting atomic operations such as compareAndSet. Loosely based off the Jetbrains JDK implementation of AtomicReferenceArray.
-
-
Constructor Summary
Constructors Constructor Description AtomicFastByteArray64(Long size)
Creates a new array of the specified size, with all elements initialized to zero. AtomicFastByteArray64(Long size, Function1<Long, Byte> init)
Creates a new array of the specified size, with all elements initialized according to the given init function. AtomicFastByteArray64(FastByteArray64 array)
Creates a copy of the given array. AtomicFastByteArray64(Array<ByteArray> array, Boolean copy)
Creates a new array from the given FastUtil BigArray, either by copying its contents or simply wrapping it. AtomicFastByteArray64(Array<ByteArray> array)
Creates a new array from the given FastUtil BigArray, either by copying its contents or simply wrapping it.
-
Method Summary
Modifier and Type Method Description Long
size()
The number of elements in this array. AtomicFastByteArray64
copy()
Produces a shallow copy of this array. Byte
get(Long index)
Returns the element at the given index. Unit
set(Long index, Byte value)
Sets the element at the given index to the given value. Byte
getAndSet(Long index, Byte new)
Sets the element at position index to the given new value and returns the old value. Byte
getAndSet(Long index, Function1<Byte, Byte> transform)
Sets the element at position index to the value resulting from applying the given transform to the old value. Byte
setAndGet(Long index, Function1<Byte, Byte> transform)
Sets the element at position index to the resulting value from applying the given transform to the old value. Boolean
compareAndSet(Long index, Byte new, Byte expected)
Sets the element at position index to the given new value if the current value matches expected. Boolean
compareAndSet(Long index, Byte new, Function2<Byte, Byte, 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, Byte value)
Eventually sets the element at the given index to the given value. AtomicByteArray64Iterator
iterator(Long index)
Returns an iterator to the element at the given index. AtomicByteArray64Iterator
iterator()
Returns an iterator to the first element in this array. -
Methods inherited from class io.github.millibyte1.array64.atomic.AtomicFastByteArray64
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
-
-
Constructor Detail
-
AtomicFastByteArray64
AtomicFastByteArray64(Long size)
Creates a new array of the specified size, with all elements initialized to zero.
-
AtomicFastByteArray64
AtomicFastByteArray64(Long size, Function1<Long, Byte> init)
Creates a new array of the specified size, with all elements initialized according to the given init function.
-
AtomicFastByteArray64
AtomicFastByteArray64(FastByteArray64 array)
Creates a copy of the given array.- Parameters:
array
- the array in question
-
AtomicFastByteArray64
AtomicFastByteArray64(Array<ByteArray> array, Boolean copy)
Creates a new array from the given FastUtil BigArray, either by copying its contents or simply wrapping it.- Parameters:
array
- the array in questioncopy
- whether to copy (true) the array or directly use it as the internal array (false)
-
-
Method Detail
-
copy
AtomicFastByteArray64 copy()
Produces a shallow copy of this array.
-
get
Byte 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, Byte 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 setvalue
- the value to set the element to
-
getAndSet
Byte getAndSet(Long index, Byte new)
- Parameters:
index
- the index of the element to setnew
- the value to set the element to
-
getAndSet
Byte getAndSet(Long index, Function1<Byte, Byte> 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 settransform
- the pure (side effect-free) transform function to apply to the old value
-
setAndGet
Byte setAndGet(Long index, Function1<Byte, Byte> 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 settransform
- the pure (side effect-free) transform function to apply to the old value
-
compareAndSet
Boolean compareAndSet(Long index, Byte new, Byte 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 setnew
- the value to set the element toexpected
- the expected value of the element
-
compareAndSet
Boolean compareAndSet(Long index, Byte new, Function2<Byte, Byte, 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 setnew
- the value to set the element topredicate
- the binary predicate to apply to the old and new values to decide whether to update
-
lazySet
Unit lazySet(Long index, Byte 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 setvalue
- the value to set the element to
-
iterator
AtomicByteArray64Iterator iterator(Long index)
Returns an iterator to the element at the given index.
-
iterator
AtomicByteArray64Iterator iterator()
Returns an iterator to the first element in this array.
-
-
-
-