Sitelet https://github.com/Vectorized/solady/blob/main/docs/utils/enumerablemaplib.md
Skip to content

Latest commit

 

History

History
1176 lines (866 loc) · 25.4 KB

File metadata and controls

1176 lines (866 loc) · 25.4 KB

EnumerableMapLib

Library for managing enumerable maps in storage.

Custom Errors

EnumerableMapKeyNotFound()

error EnumerableMapKeyNotFound()

The key does not exist in the enumerable map.

Structs

Bytes32ToBytes32Map

struct Bytes32ToBytes32Map {
    EnumerableSetLib.Bytes32Set _keys;
    mapping(bytes32 => bytes32) _values;
}

An enumerable map of bytes32 to bytes32.

Bytes32ToUint256Map

struct Bytes32ToUint256Map {
    EnumerableSetLib.Bytes32Set _keys;
    mapping(bytes32 => uint256) _values;
}

An enumerable map of bytes32 to uint256.

Bytes32ToAddressMap

struct Bytes32ToAddressMap {
    EnumerableSetLib.Bytes32Set _keys;
    mapping(bytes32 => address) _values;
}

An enumerable map of bytes32 to address.

Uint256ToBytes32Map

struct Uint256ToBytes32Map {
    EnumerableSetLib.Uint256Set _keys;
    mapping(uint256 => bytes32) _values;
}

An enumerable map of uint256 to bytes32.

Uint256ToUint256Map

struct Uint256ToUint256Map {
    EnumerableSetLib.Uint256Set _keys;
    mapping(uint256 => uint256) _values;
}

An enumerable map of uint256 to uint256.

Uint256ToAddressMap

struct Uint256ToAddressMap {
    EnumerableSetLib.Uint256Set _keys;
    mapping(uint256 => address) _values;
}

An enumerable map of uint256 to address.

AddressToBytes32Map

struct AddressToBytes32Map {
    EnumerableSetLib.AddressSet _keys;
    mapping(address => bytes32) _values;
}

An enumerable map of address to bytes32.

AddressToUint256Map

struct AddressToUint256Map {
    EnumerableSetLib.AddressSet _keys;
    mapping(address => uint256) _values;
}

An enumerable map of address to uint256.

AddressToAddressMap

struct AddressToAddressMap {
    EnumerableSetLib.AddressSet _keys;
    mapping(address => address) _values;
}

An enumerable map of address to address.

Getters / Setters

set(Bytes32ToBytes32Map,bytes32,bytes32)

function set(Bytes32ToBytes32Map storage map, bytes32 key, bytes32 value)
    internal
    returns (bool)

Adds a key-value pair to the map, or updates the value for an existing key.
Returns true if key was added to the map, that is if it was not already present.

set(Bytes32ToBytes32Map,bytes32,bytes32,uint256)

function set(
    Bytes32ToBytes32Map storage map,
    bytes32 key,
    bytes32 value,
    uint256 cap
) internal returns (bool)

Adds a key-value pair to the map, or updates the value for an existing key.
Returns true if key was added to the map, that is if it was not already present.
Reverts if the map grows bigger than the custom on-the-fly capacity cap.

remove(Bytes32ToBytes32Map,bytes32)

function remove(Bytes32ToBytes32Map storage map, bytes32 key)
    internal
    returns (bool)

Removes a key-value pair from the map.
Returns true if key was removed from the map, that is if it was present.

update(Bytes32ToBytes32Map,bytes32,bytes32,bool,uint256)

function update(
    Bytes32ToBytes32Map storage map,
    bytes32 key,
    bytes32 value,
    bool isAdd,
    uint256 cap
) internal returns (bool)

Shorthand for isAdd ? map.set(key, value, cap) : map.remove(key).

contains(Bytes32ToBytes32Map,bytes32)

function contains(Bytes32ToBytes32Map storage map, bytes32 key)
    internal
    view
    returns (bool)

Returns true if the key is in the map.

length(Bytes32ToBytes32Map)

function length(Bytes32ToBytes32Map storage map)
    internal
    view
    returns (uint256)

Returns the number of key-value pairs in the map.

at(Bytes32ToBytes32Map,uint256)

function at(Bytes32ToBytes32Map storage map, uint256 i)
    internal
    view
    returns (bytes32 key, bytes32 value)

Returns the key-value pair at index i. Reverts if i is out-of-bounds.

tryGet(Bytes32ToBytes32Map,bytes32)

function tryGet(Bytes32ToBytes32Map storage map, bytes32 key)
    internal
    view
    returns (bool exists, bytes32 value)

Tries to return the value associated with the key.

get(Bytes32ToBytes32Map,bytes32)

function get(Bytes32ToBytes32Map storage map, bytes32 key)
    internal
    view
    returns (bytes32 value)

Returns the value for the key. Reverts if the key is not found.

keys(Bytes32ToBytes32Map)

function keys(Bytes32ToBytes32Map storage map)
    internal
    view
    returns (bytes32[] memory)

Returns the keys. May run out-of-gas if the map is too big.

set(Bytes32ToUint256Map,bytes32,uint256)

function set(Bytes32ToUint256Map storage map, bytes32 key, uint256 value)
    internal
    returns (bool)

Adds a key-value pair to the map, or updates the value for an existing key.
Returns true if key was added to the map, that is if it was not already present.

set(Bytes32ToUint256Map,bytes32,uint256,uint256)

function set(
    Bytes32ToUint256Map storage map,
    bytes32 key,
    uint256 value,
    uint256 cap
) internal returns (bool)

Adds a key-value pair to the map, or updates the value for an existing key.
Returns true if key was added to the map, that is if it was not already present.
Reverts if the map grows bigger than the custom on-the-fly capacity cap.

remove(Bytes32ToUint256Map,bytes32)

function remove(Bytes32ToUint256Map storage map, bytes32 key)
    internal
    returns (bool)

Removes a key-value pair from the map.
Returns true if key was removed from the map, that is if it was present.

update(Bytes32ToUint256Map,bytes32,uint256,bool,uint256)

function update(
    Bytes32ToUint256Map storage map,
    bytes32 key,
    uint256 value,
    bool isAdd,
    uint256 cap
) internal returns (bool)

Shorthand for isAdd ? map.set(key, value, cap) : map.remove(key).

contains(Bytes32ToUint256Map,bytes32)

function contains(Bytes32ToUint256Map storage map, bytes32 key)
    internal
    view
    returns (bool)

Returns true if the key is in the map.

length(Bytes32ToUint256Map)

function length(Bytes32ToUint256Map storage map)
    internal
    view
    returns (uint256)

Returns the number of key-value pairs in the map.

at(Bytes32ToUint256Map,uint256)

function at(Bytes32ToUint256Map storage map, uint256 i)
    internal
    view
    returns (bytes32 key, uint256 value)

Returns the key-value pair at index i. Reverts if i is out-of-bounds.

tryGet(Bytes32ToUint256Map,bytes32)

function tryGet(Bytes32ToUint256Map storage map, bytes32 key)
    internal
    view
    returns (bool exists, uint256 value)

Tries to return the value associated with the key.

get(Bytes32ToUint256Map,bytes32)

function get(Bytes32ToUint256Map storage map, bytes32 key)
    internal
    view
    returns (uint256 value)

Returns the value for the key. Reverts if the key is not found.

keys(Bytes32ToUint256Map)

function keys(Bytes32ToUint256Map storage map)
    internal
    view
    returns (bytes32[] memory)

Returns the keys. May run out-of-gas if the map is too big.

set(Bytes32ToAddressMap,bytes32,address)

function set(Bytes32ToAddressMap storage map, bytes32 key, address value)
    internal
    returns (bool)

Adds a key-value pair to the map, or updates the value for an existing key.
Returns true if key was added to the map, that is if it was not already present.

set(Bytes32ToAddressMap,bytes32,address,uint256)

function set(
    Bytes32ToAddressMap storage map,
    bytes32 key,
    address value,
    uint256 cap
) internal returns (bool)

Adds a key-value pair to the map, or updates the value for an existing key.
Returns true if key was added to the map, that is if it was not already present.
Reverts if the map grows bigger than the custom on-the-fly capacity cap.

remove(Bytes32ToAddressMap,bytes32)

function remove(Bytes32ToAddressMap storage map, bytes32 key)
    internal
    returns (bool)

Removes a key-value pair from the map.
Returns true if key was removed from the map, that is if it was present.

update(Bytes32ToAddressMap,bytes32,address,bool,uint256)

function update(
    Bytes32ToAddressMap storage map,
    bytes32 key,
    address value,
    bool isAdd,
    uint256 cap
) internal returns (bool)

Shorthand for isAdd ? map.set(key, value, cap) : map.remove(key).

contains(Bytes32ToAddressMap,bytes32)

function contains(Bytes32ToAddressMap storage map, bytes32 key)
    internal
    view
    returns (bool)

Returns true if the key is in the map.

length(Bytes32ToAddressMap)

function length(Bytes32ToAddressMap storage map)
    internal
    view
    returns (uint256)

Returns the number of key-value pairs in the map.

at(Bytes32ToAddressMap,uint256)

function at(Bytes32ToAddressMap storage map, uint256 i)
    internal
    view
    returns (bytes32 key, address value)

Returns the key-value pair at index i. Reverts if i is out-of-bounds.

tryGet(Bytes32ToAddressMap,bytes32)

function tryGet(Bytes32ToAddressMap storage map, bytes32 key)
    internal
    view
    returns (bool exists, address value)

Tries to return the value associated with the key.

get(Bytes32ToAddressMap,bytes32)

function get(Bytes32ToAddressMap storage map, bytes32 key)
    internal
    view
    returns (address value)

Returns the value for the key. Reverts if the key is not found.

keys(Bytes32ToAddressMap)

function keys(Bytes32ToAddressMap storage map)
    internal
    view
    returns (bytes32[] memory)

Returns the keys. May run out-of-gas if the map is too big.

set(Uint256ToBytes32Map,uint256,bytes32)

function set(Uint256ToBytes32Map storage map, uint256 key, bytes32 value)
    internal
    returns (bool)

Adds a key-value pair to the map, or updates the value for an existing key.
Returns true if key was added to the map, that is if it was not already present.

set(Uint256ToBytes32Map,uint256,bytes32,uint256)

function set(
    Uint256ToBytes32Map storage map,
    uint256 key,
    bytes32 value,
    uint256 cap
) internal returns (bool)

Adds a key-value pair to the map, or updates the value for an existing key.
Returns true if key was added to the map, that is if it was not already present.
Reverts if the map grows bigger than the custom on-the-fly capacity cap.

remove(Uint256ToBytes32Map,uint256)

function remove(Uint256ToBytes32Map storage map, uint256 key)
    internal
    returns (bool)

Removes a key-value pair from the map.
Returns true if key was removed from the map, that is if it was present.

update(Uint256ToBytes32Map,uint256,bytes32,bool,uint256)

function update(
    Uint256ToBytes32Map storage map,
    uint256 key,
    bytes32 value,
    bool isAdd,
    uint256 cap
) internal returns (bool)

Shorthand for isAdd ? map.set(key, value, cap) : map.remove(key).

contains(Uint256ToBytes32Map,uint256)

function contains(Uint256ToBytes32Map storage map, uint256 key)
    internal
    view
    returns (bool)

Returns true if the key is in the map.

length(Uint256ToBytes32Map)

function length(Uint256ToBytes32Map storage map)
    internal
    view
    returns (uint256)

Returns the number of key-value pairs in the map.

at(Uint256ToBytes32Map,uint256)

function at(Uint256ToBytes32Map storage map, uint256 i)
    internal
    view
    returns (uint256 key, bytes32 value)

Returns the key-value pair at index i. Reverts if i is out-of-bounds.

tryGet(Uint256ToBytes32Map,uint256)

function tryGet(Uint256ToBytes32Map storage map, uint256 key)
    internal
    view
    returns (bool exists, bytes32 value)

Tries to return the value associated with the key.

get(Uint256ToBytes32Map,uint256)

function get(Uint256ToBytes32Map storage map, uint256 key)
    internal
    view
    returns (bytes32 value)

Returns the value for the key. Reverts if the key is not found.

keys(Uint256ToBytes32Map)

function keys(Uint256ToBytes32Map storage map)
    internal
    view
    returns (uint256[] memory)

Returns the keys. May run out-of-gas if the map is too big.

set(Uint256ToUint256Map,uint256,uint256)

function set(Uint256ToUint256Map storage map, uint256 key, uint256 value)
    internal
    returns (bool)

Adds a key-value pair to the map, or updates the value for an existing key.
Returns true if key was added to the map, that is if it was not already present.

set(Uint256ToUint256Map,uint256,uint256,uint256)

function set(
    Uint256ToUint256Map storage map,
    uint256 key,
    uint256 value,
    uint256 cap
) internal returns (bool)

Adds a key-value pair to the map, or updates the value for an existing key.
Returns true if key was added to the map, that is if it was not already present.
Reverts if the map grows bigger than the custom on-the-fly capacity cap.

remove(Uint256ToUint256Map,uint256)

function remove(Uint256ToUint256Map storage map, uint256 key)
    internal
    returns (bool)

Removes a key-value pair from the map.
Returns true if key was removed from the map, that is if it was present.

update(Uint256ToUint256Map,uint256,uint256,bool,uint256)

function update(
    Uint256ToUint256Map storage map,
    uint256 key,
    uint256 value,
    bool isAdd,
    uint256 cap
) internal returns (bool)

Shorthand for isAdd ? map.set(key, value, cap) : map.remove(key).

contains(Uint256ToUint256Map,uint256)

function contains(Uint256ToUint256Map storage map, uint256 key)
    internal
    view
    returns (bool)

Returns true if the key is in the map.

length(Uint256ToUint256Map)

function length(Uint256ToUint256Map storage map)
    internal
    view
    returns (uint256)

Returns the number of key-value pairs in the map.

at(Uint256ToUint256Map,uint256)

function at(Uint256ToUint256Map storage map, uint256 i)
    internal
    view
    returns (uint256 key, uint256 value)

Returns the key-value pair at index i. Reverts if i is out-of-bounds.

tryGet(Uint256ToUint256Map,uint256)

function tryGet(Uint256ToUint256Map storage map, uint256 key)
    internal
    view
    returns (bool exists, uint256 value)

Tries to return the value associated with the key.

get(Uint256ToUint256Map,uint256)

function get(Uint256ToUint256Map storage map, uint256 key)
    internal
    view
    returns (uint256 value)

Returns the value for the key. Reverts if the key is not found.

keys(Uint256ToUint256Map)

function keys(Uint256ToUint256Map storage map)
    internal
    view
    returns (uint256[] memory)

Returns the keys. May run out-of-gas if the map is too big.

set(Uint256ToAddressMap,uint256,address)

function set(Uint256ToAddressMap storage map, uint256 key, address value)
    internal
    returns (bool)

Adds a key-value pair to the map, or updates the value for an existing key.
Returns true if key was added to the map, that is if it was not already present.

set(Uint256ToAddressMap,uint256,address,uint256)

function set(
    Uint256ToAddressMap storage map,
    uint256 key,
    address value,
    uint256 cap
) internal returns (bool)

Adds a key-value pair to the map, or updates the value for an existing key.
Returns true if key was added to the map, that is if it was not already present.
Reverts if the map grows bigger than the custom on-the-fly capacity cap.

remove(Uint256ToAddressMap,uint256)

function remove(Uint256ToAddressMap storage map, uint256 key)
    internal
    returns (bool)

Removes a key-value pair from the map.
Returns true if key was removed from the map, that is if it was present.

update(Uint256ToAddressMap,uint256,address,bool,uint256)

function update(
    Uint256ToAddressMap storage map,
    uint256 key,
    address value,
    bool isAdd,
    uint256 cap
) internal returns (bool)

Shorthand for isAdd ? map.set(key, value, cap) : map.remove(key).

contains(Uint256ToAddressMap,uint256)

function contains(Uint256ToAddressMap storage map, uint256 key)
    internal
    view
    returns (bool)

Returns true if the key is in the map.

length(Uint256ToAddressMap)

function length(Uint256ToAddressMap storage map)
    internal
    view
    returns (uint256)

Returns the number of key-value pairs in the map.

at(Uint256ToAddressMap,uint256)

function at(Uint256ToAddressMap storage map, uint256 i)
    internal
    view
    returns (uint256 key, address value)

Returns the key-value pair at index i. Reverts if i is out-of-bounds.

tryGet(Uint256ToAddressMap,uint256)

function tryGet(Uint256ToAddressMap storage map, uint256 key)
    internal
    view
    returns (bool exists, address value)

Tries to return the value associated with the key.

get(Uint256ToAddressMap,uint256)

function get(Uint256ToAddressMap storage map, uint256 key)
    internal
    view
    returns (address value)

Returns the value for the key. Reverts if the key is not found.

keys(Uint256ToAddressMap)

function keys(Uint256ToAddressMap storage map)
    internal
    view
    returns (uint256[] memory)

Returns the keys. May run out-of-gas if the map is too big.

set(AddressToBytes32Map,address,bytes32)

function set(AddressToBytes32Map storage map, address key, bytes32 value)
    internal
    returns (bool)

Adds a key-value pair to the map, or updates the value for an existing key.
Returns true if key was added to the map, that is if it was not already present.

set(AddressToBytes32Map,address,bytes32,uint256)

function set(
    AddressToBytes32Map storage map,
    address key,
    bytes32 value,
    uint256 cap
) internal returns (bool)

Adds a key-value pair to the map, or updates the value for an existing key.
Returns true if key was added to the map, that is if it was not already present.
Reverts if the map grows bigger than the custom on-the-fly capacity cap.

remove(AddressToBytes32Map,address)

function remove(AddressToBytes32Map storage map, address key)
    internal
    returns (bool)

Removes a key-value pair from the map.
Returns true if key was removed from the map, that is if it was present.

update(AddressToBytes32Map,address,bytes32,bool,uint256)

function update(
    AddressToBytes32Map storage map,
    address key,
    bytes32 value,
    bool isAdd,
    uint256 cap
) internal returns (bool)

Shorthand for isAdd ? map.set(key, value, cap) : map.remove(key).

contains(AddressToBytes32Map,address)

function contains(AddressToBytes32Map storage map, address key)
    internal
    view
    returns (bool)

Returns true if the key is in the map.

length(AddressToBytes32Map)

function length(AddressToBytes32Map storage map)
    internal
    view
    returns (uint256)

Returns the number of key-value pairs in the map.

at(AddressToBytes32Map,uint256)

function at(AddressToBytes32Map storage map, uint256 i)
    internal
    view
    returns (address key, bytes32 value)

Returns the key-value pair at index i. Reverts if i is out-of-bounds.

tryGet(AddressToBytes32Map,address)

function tryGet(AddressToBytes32Map storage map, address key)
    internal
    view
    returns (bool exists, bytes32 value)

Tries to return the value associated with the key.

get(AddressToBytes32Map,address)

function get(AddressToBytes32Map storage map, address key)
    internal
    view
    returns (bytes32 value)

Returns the value for the key. Reverts if the key is not found.

keys(AddressToBytes32Map)

function keys(AddressToBytes32Map storage map)
    internal
    view
    returns (address[] memory)

Returns the keys. May run out-of-gas if the map is too big.

set(AddressToUint256Map,address,uint256)

function set(AddressToUint256Map storage map, address key, uint256 value)
    internal
    returns (bool)

Adds a key-value pair to the map, or updates the value for an existing key.
Returns true if key was added to the map, that is if it was not already present.

set(AddressToUint256Map,address,uint256,uint256)

function set(
    AddressToUint256Map storage map,
    address key,
    uint256 value,
    uint256 cap
) internal returns (bool)

Adds a key-value pair to the map, or updates the value for an existing key.
Returns true if key was added to the map, that is if it was not already present.
Reverts if the map grows bigger than the custom on-the-fly capacity cap.

remove(AddressToUint256Map,address)

function remove(AddressToUint256Map storage map, address key)
    internal
    returns (bool)

Removes a key-value pair from the map.
Returns true if key was removed from the map, that is if it was present.

update(AddressToUint256Map,address,uint256,bool,uint256)

function update(
    AddressToUint256Map storage map,
    address key,
    uint256 value,
    bool isAdd,
    uint256 cap
) internal returns (bool)

Shorthand for isAdd ? map.set(key, value, cap) : map.remove(key).

contains(AddressToUint256Map,address)

function contains(AddressToUint256Map storage map, address key)
    internal
    view
    returns (bool)

Returns true if the key is in the map.

length(AddressToUint256Map)

function length(AddressToUint256Map storage map)
    internal
    view
    returns (uint256)

Returns the number of key-value pairs in the map.

at(AddressToUint256Map,uint256)

function at(AddressToUint256Map storage map, uint256 i)
    internal
    view
    returns (address key, uint256 value)

Returns the key-value pair at index i. Reverts if i is out-of-bounds.

tryGet(AddressToUint256Map,address)

function tryGet(AddressToUint256Map storage map, address key)
    internal
    view
    returns (bool exists, uint256 value)

Tries to return the value associated with the key.

get(AddressToUint256Map,address)

function get(AddressToUint256Map storage map, address key)
    internal
    view
    returns (uint256 value)

Returns the value for the key. Reverts if the key is not found.

keys(AddressToUint256Map)

function keys(AddressToUint256Map storage map)
    internal
    view
    returns (address[] memory)

Returns the keys. May run out-of-gas if the map is too big.

set(AddressToAddressMap,address,address)

function set(AddressToAddressMap storage map, address key, address value)
    internal
    returns (bool)

Adds a key-value pair to the map, or updates the value for an existing key.
Returns true if key was added to the map, that is if it was not already present.

set(AddressToAddressMap,address,address,uint256)

function set(
    AddressToAddressMap storage map,
    address key,
    address value,
    uint256 cap
) internal returns (bool)

Adds a key-value pair to the map, or updates the value for an existing key.
Returns true if key was added to the map, that is if it was not already present.
Reverts if the map grows bigger than the custom on-the-fly capacity cap.

remove(AddressToAddressMap,address)

function remove(AddressToAddressMap storage map, address key)
    internal
    returns (bool)

Removes a key-value pair from the map.
Returns true if key was removed from the map, that is if it was present.

update(AddressToAddressMap,address,address,bool,uint256)

function update(
    AddressToAddressMap storage map,
    address key,
    address value,
    bool isAdd,
    uint256 cap
) internal returns (bool)

Shorthand for isAdd ? map.set(key, value, cap) : map.remove(key).

contains(AddressToAddressMap,address)

function contains(AddressToAddressMap storage map, address key)
    internal
    view
    returns (bool)

Returns true if the key is in the map.

length(AddressToAddressMap)

function length(AddressToAddressMap storage map)
    internal
    view
    returns (uint256)

Returns the number of key-value pairs in the map.

at(AddressToAddressMap,uint256)

function at(AddressToAddressMap storage map, uint256 i)
    internal
    view
    returns (address key, address value)

Returns the key-value pair at index i. Reverts if i is out-of-bounds.

tryGet(AddressToAddressMap,address)

function tryGet(AddressToAddressMap storage map, address key)
    internal
    view
    returns (bool exists, address value)

Tries to return the value associated with the key.

get(AddressToAddressMap,address)

function get(AddressToAddressMap storage map, address key)
    internal
    view
    returns (address value)

Returns the value for the key. Reverts if the key is not found.

keys(AddressToAddressMap)

function keys(AddressToAddressMap storage map)
    internal
    view
    returns (address[] memory)

Returns the keys. May run out-of-gas if the map is too big.