jsat.utils.concurrent
Class AtomicDoubleArray
- java.lang.Object
-
- jsat.utils.concurrent.AtomicDoubleArray
-
- All Implemented Interfaces:
- java.io.Serializable
public class AtomicDoubleArray extends java.lang.Object implements java.io.SerializableProvides a double array that can have individual values updated atomically. It is backed by and mimics the implementation ofAtomicLongArray. As such, the methods have the same documentation- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description AtomicDoubleArray(double[] array)Creates a new AtomixDouble Array that is of the same length as the input array.AtomicDoubleArray(int length)Creates a new AtomicDoubleArray of the given length, with all values initialized to zero
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description doubleaccumulateAndGet(int i, double x, java.util.function.DoubleBinaryOperator accumulatorFunction)Atomically updates the element at indexiwith the results of applying the given function to the current and given values, returning the updated value.doubleaddAndGet(int i, double delta)Atomically adds the given value to the element at indexi.booleancompareAndSet(int i, double expected, double update)Atomically sets the element at positionito the given updated value if the current value==the expected value.voidfill(double value)This is a convenience method to set every value in this array to a specified valuedoubleget(int i)Gets the current value at positioni.doublegetAndAccumulate(int i, double x, java.util.function.DoubleBinaryOperator accumulatorFunction)Atomically updates the element at indexiwith the results of applying the given function to the current and given values, returning the previous value.doublegetAndAdd(int i, double delta)Atomically adds the given value to the element at indexi.doublegetAndDecrement(int i)Atomically decrements by one the element at indexi.doublegetAndIncrement(int i)Atomically increments by one the element at indexi.doublegetAndSet(int i, double newValue)Atomically sets the element at positionito the given value and returns the old value.doublegetAndUpdate(int i, java.util.function.DoubleUnaryOperator updateFunction)Atomically updates the element at indexiwith the results of applying the given function, returning the previous value.voidlazySet(int i, double newValue)Eventually sets the element at positionito the given value.intlength()Returns the length of the array.voidset(int i, double newValue)Sets the element at positionito the given value.doubleupdateAndGet(int i, java.util.function.DoubleUnaryOperator updateFunction)Atomically updates the element at indexiwith the results of applying the given function, returning the updated value.booleanweakCompareAndSet(int i, double expected, double update)Atomically sets the element at positionito the given updated value if the current value==the expected value.
-
-
-
Constructor Detail
-
AtomicDoubleArray
public AtomicDoubleArray(int length)
Creates a new AtomicDoubleArray of the given length, with all values initialized to zero- Parameters:
length- the length of the array
-
AtomicDoubleArray
public AtomicDoubleArray(double[] array)
Creates a new AtomixDouble Array that is of the same length as the input array. The values will be copied into the new object- Parameters:
array- the array of values to copy
-
-
Method Detail
-
getAndIncrement
public double getAndIncrement(int i)
Atomically increments by one the element at indexi.- Parameters:
i- the index- Returns:
- the previous value
-
getAndDecrement
public double getAndDecrement(int i)
Atomically decrements by one the element at indexi.- Parameters:
i- the index- Returns:
- the previous value
-
getAndAdd
public double getAndAdd(int i, double delta)Atomically adds the given value to the element at indexi.- Parameters:
i- the indexdelta- the value to add- Returns:
- the previous value
-
addAndGet
public double addAndGet(int i, double delta)Atomically adds the given value to the element at indexi.- Parameters:
i- the indexdelta- the value to add- Returns:
- the updated value
-
getAndSet
public double getAndSet(int i, double newValue)Atomically sets the element at positionito the given value and returns the old value.- Parameters:
i- the indexnewValue- the new value- Returns:
- the previous value
-
set
public void set(int i, double newValue)Sets the element at positionito the given value.- Parameters:
i- the indexnewValue- the new value
-
lazySet
public void lazySet(int i, double newValue)Eventually sets the element at positionito the given value.- Parameters:
i- the indexnewValue- the new value
-
compareAndSet
public boolean compareAndSet(int i, double expected, double update)Atomically sets the element at positionito the given updated value if the current value==the expected value.- Parameters:
i- the indexexpected- the expected valueupdate- the new value- Returns:
- true if successful. False return indicates that the actual value was not equal to the expected value.
-
weakCompareAndSet
public boolean weakCompareAndSet(int i, double expected, double update)Atomically sets the element at positionito the given updated value if the current value==the expected value.May fail spuriously and does not provide ordering guarantees, so is only rarely an appropriate alternative to
compareAndSet.- Parameters:
i- the indexexpected- the expected valueupdate- the new value- Returns:
- true if successful.
-
updateAndGet
public final double updateAndGet(int i, java.util.function.DoubleUnaryOperator updateFunction)Atomically updates the element at indexiwith 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.- Parameters:
i- the indexupdateFunction- a side-effect-free function- Returns:
- the updated value
-
getAndUpdate
public final double getAndUpdate(int i, java.util.function.DoubleUnaryOperator updateFunction)Atomically updates the element at indexiwith the results of applying the given function, returning the previous value. The function should be side-effect-free, since it may be re-applied when attempted updates fail due to contention among threads.- Parameters:
i- the indexupdateFunction- a side-effect-free function- Returns:
- the previous value
-
getAndAccumulate
public final double getAndAccumulate(int i, double x, java.util.function.DoubleBinaryOperator accumulatorFunction)Atomically updates the element at indexiwith the results of applying the given function to the current and given values, returning the previous value. The function should be side-effect-free, since it may be re-applied when attempted updates fail due to contention among threads. The function is applied with the current value at indexias its first argument, and the given update as the second argument.- Parameters:
i- the indexx- the update valueaccumulatorFunction- a side-effect-free function of two arguments- Returns:
- the previous value
-
accumulateAndGet
public final double accumulateAndGet(int i, double x, java.util.function.DoubleBinaryOperator accumulatorFunction)Atomically updates the element at indexiwith the results of applying the given function to the current and given values, 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. The function is applied with the current value at indexias its first argument, and the given update as the second argument.- Parameters:
i- the indexx- the update valueaccumulatorFunction- a side-effect-free function of two arguments- Returns:
- the updated value
-
get
public double get(int i)
Gets the current value at positioni.- Parameters:
i- the index- Returns:
- the current value
-
length
public int length()
Returns the length of the array.- Returns:
- the length of the array
-
fill
public void fill(double value)
This is a convenience method to set every value in this array to a specified value- Parameters:
value- the value fill with
-
-
DataMelt 3.0 © DataMelt by jWork.ORG