Cumulative U256

Concurrent Delta Friendly uint256

U256Cumulative is a concurrent variable that supports concurrent addition and subtraction. It is conceptionally similar to an atomic integer but with one major constraint: the value can be only updated. Attempting to invoke timing-dependent operations like read()on the variable while being updated by other threads will result in a transaction rollback.

TheU256Cum contract is designed for handling cumulative operations in full parallel. It has both minimum and maximum bounds and allows concurrent delta changes. Out-of-limit delta changes will fail to ensure that the variable stays within its prescribed bounds.

Note: It is recommended to check the returned value after adding a delta update.

Constructor

constructor(uint256 minv, uint256 maxv)

constructor(uint256 minv, uint256 maxv)

Constructor to initialize the U256Cumulative variable with specified minimum and maximum bounds.

  • Parameters:

    • minv (type: uint256): The minimum bound of the cumulative value.

    • maxv (type: uint256): The maximum bound of the cumulative value.

Public Functions

peek

function peek() public returns (uint256)

Get the latest committed value of the cumulative variable.

  • Returns:

    • uint256: The latest committed value of the cumulative variable.

get

function get() public returns (uint256)

Get the current value of the cumulative variable.

  • Returns:

    • uint256: The current value of the cumulative variable.

add

function add(uint256 delta ) public returns (bool)

Add the given value to the cumulative variable.

  • Parameters:

    • delta (type: uint256): The value to be added to the cumulative variable.

  • Returns:

    • bool: A boolean indicating the success of the operation.

sub

function sub(uint256 delta) public returns (bool)

Subtract the given value from the variable.

  • Parameters:

    • delta (type: uint256): The value to be subtracted from the cumulative variable.

  • Returns:

    • bool: A boolean indicating the success of the operation.

min

function min() public returns (uint256)

Get the minimum bound of the variable.

  • Returns:

    • uint256: The minimum bound of the cumulative variable.

max

function max() public returns (uint256)

Get the maximum bound of the variable.

  • Returns:

    • uint256: The maximum bound of the variable.

Last updated