|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.rit.pj.reduction.SharedCharacterArray
public class SharedCharacterArray
Class SharedCharacterArray provides an array reduction variable with elements of type char.
Class SharedCharacterArray is multiple thread safe. The methods use lock-free atomic compare-and-set.
Note: Class SharedCharacterArray is implemented using class java.util.concurrent.atomic.AtomicIntegerArray. Each character array element is stored as an int whose values are restricted to the range of type char.
| Constructor Summary | |
|---|---|
SharedCharacterArray(char[] array)
Construct a new character array reduction variable whose elements are copied from the given array. |
|
SharedCharacterArray(int len)
Construct a new character array reduction variable with the given length. |
|
| Method Summary | |
|---|---|
char |
addAndGet(int i,
char value)
Add the given value to this array reduction variable at the given index and return the new value. |
boolean |
compareAndSet(int i,
char expect,
char update)
Atomically set this array reduction variable at the given index to the given updated value if the current value equals the expected value. |
char |
decrementAndGet(int i)
Subtract one from this array reduction variable at the given index and return the new value. |
char |
get(int i)
Returns this array reduction variable's current value at the given index. |
char |
getAndAdd(int i,
char value)
Add the given value to this array reduction variable at the given index and return the previous value. |
char |
getAndDecrement(int i)
Subtract one from this array reduction variable at the given index and return the previous value. |
char |
getAndIncrement(int i)
Add one to this array reduction variable at the given index and return the previous value. |
char |
getAndSet(int i,
char value)
Set this array reduction variable at the given index to the given value and return the previous value. |
char |
incrementAndGet(int i)
Add one to this array reduction variable at the given index and return the new value. |
int |
length()
Returns this array reduction variable's length. |
void |
reduce(char[] src,
CharacterOp op)
Combine this array reduction variable with the given array using the given operation. |
void |
reduce(int dstoff,
char[] src,
int srcoff,
int len,
CharacterOp op)
Combine a portion of this array reduction variable with a portion of the given array using the given operation. |
char |
reduce(int i,
char value,
CharacterOp op)
Combine this array reduction variable at the given index with the given value using the given operation. |
void |
set(int i,
char value)
Set this array reduction variable at the given index to the given value. |
String |
toString()
Returns a string version of this array reduction variable. |
boolean |
weakCompareAndSet(int i,
char expect,
char update)
Atomically set this array reduction variable at the given index to the given updated value if the current value equals the expected value. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public SharedCharacterArray(int len)
len - Length.
NegativeArraySizeException - (unchecked exception) Thrown if len < 0.public SharedCharacterArray(char[] array)
array - Array to copy.
NullPointerException - (unchecked exception) Thrown if array is null.| Method Detail |
|---|
public int length()
public char get(int i)
i - Index.
public void set(int i,
char value)
i - Index.value - New value.
public char getAndSet(int i,
char value)
i - Index.value - New value.
public boolean compareAndSet(int i,
char expect,
char update)
i - Index.expect - Expected value.update - Updated value.
public boolean weakCompareAndSet(int i,
char expect,
char update)
i - Index.expect - Expected value.update - Updated value.
public char getAndIncrement(int i)
i - Index.
public char getAndDecrement(int i)
i - Index.
public char getAndAdd(int i,
char value)
i - Index.value - Value to add.
public char incrementAndGet(int i)
i - Index.
public char decrementAndGet(int i)
i - Index.
public char addAndGet(int i,
char value)
i - Index.value - Value to add.
public char reduce(int i,
char value,
CharacterOp op)
i - Index.value - Value.op - Binary operation.
public void reduce(char[] src,
CharacterOp op)
The reduce() method is multiple thread safe on a per-element basis. Each individual array element is updated atomically, but the array as a whole is not updated atomically.
src - Source array.op - Binary operation.
NullPointerException - (unchecked exception) Thrown if src is null. Thrown if
op is null.
IndexOutOfBoundsException - (unchecked exception) Thrown if any array index would be out of
bounds.
public void reduce(int dstoff,
char[] src,
int srcoff,
int len,
CharacterOp op)
The reduce() method is multiple thread safe on a per-element basis. Each individual array element is updated atomically, but the array as a whole is not updated atomically.
dstoff - Index of first element to update in this array.src - Source array.srcoff - Index of first element to update from in the source
array.len - Number of array elements to update.op - Binary operation.
NullPointerException - (unchecked exception) Thrown if src is null. Thrown if
op is null.
IndexOutOfBoundsException - (unchecked exception) Thrown if len < 0. Thrown if any
array index would be out of bounds.public String toString()
toString in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||