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 are not designed for this purpose and may behave unpredictably in 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 Arcology's concurrent framework, not the EVM.
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
Initiates communication with the external contract.
Public Functions
length
Retrieve the length of the container.
Returns:
uint256
: The length of the container.
peek
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
Removes and returns the last element of the container.
Returns:
bytes
: The data of the removed element.
setByIndex
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
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
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
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
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
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
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
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
Clear all data stored.
Returns:
true
if all the data was successfully deleted,false
otherwise.
forEach
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