The Bool contract is a concurrent array specialized for storing boolean values. It inherits from the Base contract to utilize container functionalities for boolean storage.
Constructor
constructor()
Functions
push
functionpush(bool elem) publicvirtual
Add a boolean element to the concurrent array.
Parameters:
elem: The boolean element to add to the array.
pop
functionpop() publicvirtualreturns (bool)
Remove and return the last boolean element from the concurrent array.
Retrieve the boolean element at the given index from the concurrent array.
Parameters:
idx: The index of the Boolean element to retrieve.
set
functionset(uint256 idx,bool elem) public
Set the boolean element at the given index in the concurrent array.
Parameters:
idx: The index where the boolean element should be stored.
elem: The boolean element to be stored at the specified index.
Example
The examples below demonstrates the usage of the Bool contract, which is a concurrent array specialized for storing boolean values, and the test cases in BoolTest verify the correctness of its functionalities for adding, retrieving, setting, and removing boolean elements.
The code example illustrates demonstrates how this concurrent data structure can be effectively used for managing the Boolean values within a smart contract.
The contract below showcases the ability to perform concurrent processing using Arcology's Multiprocessing feature. The 'Appender' function is executed in parallel using two separate Multiprocess instances, allowing for efficient concurrent updates to the "container" data structure.
This demonstrates how Arcology's concurrent programming capabilities can significantly improve the performance and efficiency of smart contracts, especially when handling multiple tasks concurrently.
import"./Bool.sol";import"./Multiprocess.sol";contract MultiprocessConcurrentBool { Bool container =newBool(); // Create a new "Bool" array Multiprocess mp ; // Declare two instances of the "Multiprocess" contract. Multiprocess mp2;// Entry point function for the contract's execution.functioncall() public { // Create a new "Multiprocess" instance "mp" with concurrency level 2. mp =newMultiprocess(2);// Create another "Multiprocess" instance "mp2" with concurrency level 2. mp2 =newMultiprocess(2);// Push two "appender" functions calls into "mp" for concurrent execution. mp.push(4000000,address(this), abi.encodeWithSignature("appender()")); mp.push(4000000,address(this), abi.encodeWithSignature("appender()"));// Execute the "appender" functions concurrently. mp.run();// Ensure that "container" length is 2 after the concurrent execution.require(container.length() ==2); // Create a new "Multiprocess" instance "mp2" with concurrency level 2. mp2 =newMultiprocess(2);// Push two "appender" function calls into "mp2" for concurrent execution. mp2.push(4000000,address(this), abi.encodeWithSignature("appender()")); mp2.push(4000000,address(this), abi.encodeWithSignature("appender()")); mp2.run(); // Execute the "appender" functions in "mp2" concurrently.require(container.length() ==4); // Ensure the length is 4.// Append a single "true" value to "container" outside the "Multiprocess". container.push(true);require(container.length() ==5); // Ensure that "container" length is 5 }// Function to append a "true" value to "container".functionappender() public { container.push(true); }}