🏁
Concurrent Programming Guide
  • Welcome
  • Overview
  • data structure
    • Cumulative Integer
    • Base
    • Arrays
    • Ordered Maps
  • utility
    • Multiprocessor
    • Runtime
    • Storage
  • Examples
    • Contract Examples
Powered by GitBook
On this page
  • Issues with Mapping in Solidity
  • Concurrent Maps
  • Supported Data Types
  • Address U256Cum
  1. data structure

Ordered Maps

Arcology Hash Maps

In Arcology, the map functions as a data structure with the properties of an ordered map.

Issues with Mapping in Solidity

Solidity's mapping is similar to hash maps in other languages, but it has some major differences comparing to them:

  • Direct Iteration: Mappings do not support direct iteration. To iterate over keys or values, you need to maintain an auxiliary data structure, like an array, to store the keys separately.

  • Existence Check: There's no direct method to check if a key exists. You have to infer the existence based on the default value for the value type or maintain a separate boolean mapping.

  • Deletion of Keys: You can delete a key in a mapping using the delete keyword, but it only resets the value to its default state.

  • Storage-Based: Solidity mappings are primarily used for storing data on the blockchain. Each key-value pair is stored in the contract's storage, which is persistent and incurs storage costs.

Concurrent Maps

In Arcology, the ordered map permits access to elements via keys and supports iteration in the order of insertion. Additionally, the maps offer enhanced functionalities such as key and value retrieval by index and explicit verification of key presence. Arcology's Hash Maps can be configured as in-memory or in-storage, offering greater flexibility in data management.

Supported Data Types

Currently, the following data types are supported by the container:

  • Address / Boolean

  • Address / U256

  • Address / Cumulative U256

  • Hash / Cumulative U256

  • String / U256

  • U256 / U256

Address U256Cum

Address U256Cum is particularly useful because of it allows concurrent write to the same value without breaking the commutative property. The values have the same property as

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.8.0 <0.9.0;

import "./AddressUint256.sol";
import "../multiprocess/Multiprocess.sol";

contract AddressU256MapTest {
    AddressUint256Map map = new AddressUint256Map();
    constructor() {     
        address addr1 = 0x1111111110123456789012345678901234567890;
        address addr2 = 0x2222222220123456789012345678901234567890;
        address addr3 = 0x3333337890123456789012345678901234567890;
        address addr4 = 0x4444444890123456789012345678901234567890;

        require(map.nonNilCount() == 0); 

        map.set(addr1, 11);  
        map.set(addr2, 21);
        map.set(addr3, 31);
        require(map.nonNilCount() == 3); 
    }
}

Custom Types: You can always derive maps of custom types from the Base contract. Developers can build their own HashMap of custom types using the base container provided by Arcology.

PreviousArraysNextMultiprocessor

Last updated 1 month ago