Base

Foundation of Concurrency Data Structures

When it comes to parallel processing, the built-in Solidity data structures don't provide the necessary protection for state consistency. They aren't designed for that purpose and may act adversely under parallel execution environments.

Arcology's concurrent containers are lockless data structures specifically designed to handle concurrent data manipulation and they are different from native data structures in a number of ways:

  • The containers are managed by the concurrent framework.

  • They can only be accessed through the concurrent APIs.

  • Their behaviors under concurrent environments are strictly defined.

Base Contract

The Base contract a hybrid concurrent data structure, functioning as a map set behind the scenes. It is the foundation of all other containers on Arcology.

To maintain timing independency, the container's element order is determined only when timing-dependent functions, such as pop() or length()are called or the execution is completed. In case of conflicting transactions, automatic reversion occurs to safeguard the consistency of the state.

This key design guarantees that the container's state remains unchanged regardless of the timing variations in transactions, ensuring the integrity and consistency of the container's data under all circumstances.

Note: Concurrent calls to the functions likepop()andlength() aren't recommended, as these operations are timing-independent and may lead to conflicts.

Constructor

constructor()

Initiates communication with the external contract.

Public Functions

length

function length() public returns (uint256)

Retrieve the length of the container.

  • Returns:

    • uint256: The length of the container.

peek

function peek() public returns (bytes memory)

Retrieve the committed length of the container. This usually is the length at the previous block height.

  • Returns:

    • bytes: The latest committed length of the container. This function is thread-safe.

popBack

function popBack() public virtual returns (bytes memory)

Removes and returns the last element of the container.

  • Returns:

    • bytes: The data of the removed element.

setByIndex

function setByIndex(uint256 idx, bytes memory encoded) public returns (bool)

Set the data at the given index in the container.

  • Parameters:

    • idx: The index where the data should be stored.

    • encoded: The data to be stored.

  • Returns:

    • true if the data was successfully updated, false otherwise.

keyByIndex

function keyByIndex(uint256 idx) public returns (bytes memory)

Retrieves the key associated with the given index in the concurrent container.

  • Parameters:

    • idx: The index for which to retrieve the key.

  • Returns:

    • bytes: The key associated with the given index.

indexByKey

function indexByKey(bytes memory key) public returns (uint256)

Retrieves the index associated with the given key in the concurrent container.

  • Parameters:

    • key: The key for which to retrieve the index.

  • Returns:

    • uint256: The index associated with the given key.

setByKey

function setByKey(bytes memory key, bytes memory elem) public returns (bool)

Set the data associated with the given key in the container.

  • Parameters:

    • key: The key associated with the data.

    • elem: The data to be stored.

  • Returns:

    • true if the data was successfully updated, false otherwise.

delByIndex

function delByIndex(uint256 idx) public returns (bool)

Delete the data at the given index in the container.

  • Parameters:

    • idx: The index of the data to be deleted.

  • Returns:

    • true if the data was successfully deleted, false otherwise.

delByKey

function delByKey(bytes memory key) public returns (bool)

Delete the data associated with the given key from the container.

  • Parameters:

    • key: The key associated with the data to be deleted.

  • Returns:

    • true if the data was successfully deleted, false otherwise.

getByIndex

function getByIndex(uint256 idx) public virtual returns (bytes memory)

Retrieve the data at the given index from the container.

  • Parameters:

    • idx: The index of the data to retrieve.

  • Returns:

    • bytes: The data stored at the specified index.

getByKey

function getByKey(bytes memory key) public returns (bytes memory)

Retrieve the data associated with the given key from the container.

  • Parameters:

    • key: The key associated with the data to retrieve.

  • Returns:

    • bytes: The data stored at the specified key.

clear

function clear() public returns (bool)

Clear all data stored.

  • Returns:

    • true if all the data was successfully deleted, false otherwise.

forEach

function forEach(bytes memory data) public

Execute a custom operation on the container's data stored.

  • Parameters:

    • data: Arbitrary call with the data to be used in the custom operation.

Last updated