1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000 |
- // SPDX-License-Identifier: MIT
- // OpenZeppelin Contracts (last updated v5.3.0) (utils/structs/EnumerableMap.sol)
- // This file was procedurally generated from scripts/generate/templates/EnumerableMap.js.
- pragma solidity ^0.8.20;
- import {EnumerableSet} from "./EnumerableSet.sol";
- /**
- * @dev Library for managing an enumerable variant of Solidity's
- * https://solidity.readthedocs.io/en/latest/types.html#mapping-types[`mapping`]
- * type.
- *
- * Maps have the following properties:
- *
- * - Entries are added, removed, and checked for existence in constant time
- * (O(1)).
- * - Entries are enumerated in O(n). No guarantees are made on the ordering.
- * - Map can be cleared (all entries removed) in O(n).
- *
- * ```solidity
- * contract Example {
- * // Add the library methods
- * using EnumerableMap for EnumerableMap.UintToAddressMap;
- *
- * // Declare a set state variable
- * EnumerableMap.UintToAddressMap private myMap;
- * }
- * ```
- *
- * The following map types are supported:
- *
- * - `uint256 -> address` (`UintToAddressMap`) since v3.0.0
- * - `address -> uint256` (`AddressToUintMap`) since v4.6.0
- * - `bytes32 -> bytes32` (`Bytes32ToBytes32Map`) since v4.6.0
- * - `uint256 -> uint256` (`UintToUintMap`) since v4.7.0
- * - `bytes32 -> uint256` (`Bytes32ToUintMap`) since v4.7.0
- * - `uint256 -> bytes32` (`UintToBytes32Map`) since v5.1.0
- * - `address -> address` (`AddressToAddressMap`) since v5.1.0
- * - `address -> bytes32` (`AddressToBytes32Map`) since v5.1.0
- * - `bytes32 -> address` (`Bytes32ToAddressMap`) since v5.1.0
- *
- * [WARNING]
- * ====
- * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
- * unusable.
- * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
- *
- * In order to clean an EnumerableMap, you can either remove all elements one by one or create a fresh instance using an
- * array of EnumerableMap.
- * ====
- */
- library EnumerableMap {
- using EnumerableSet for EnumerableSet.Bytes32Set;
- // To implement this library for multiple types with as little code repetition as possible, we write it in
- // terms of a generic Map type with bytes32 keys and values. The Map implementation uses private functions,
- // and user-facing implementations such as `UintToAddressMap` are just wrappers around the underlying Map.
- // This means that we can only create new EnumerableMaps for types that fit in bytes32.
- /**
- * @dev Query for a nonexistent map key.
- */
- error EnumerableMapNonexistentKey(bytes32 key);
- struct Bytes32ToBytes32Map {
- // Storage of keys
- EnumerableSet.Bytes32Set _keys;
- mapping(bytes32 key => bytes32) _values;
- }
- /**
- * @dev Adds a key-value pair to a map, or updates the value for an existing
- * key. O(1).
- *
- * Returns true if the key was added to the map, that is if it was not
- * already present.
- */
- function set(Bytes32ToBytes32Map storage map, bytes32 key, bytes32 value) internal returns (bool) {
- map._values[key] = value;
- return map._keys.add(key);
- }
- /**
- * @dev Removes a key-value pair from a map. O(1).
- *
- * Returns true if the key was removed from the map, that is if it was present.
- */
- function remove(Bytes32ToBytes32Map storage map, bytes32 key) internal returns (bool) {
- delete map._values[key];
- return map._keys.remove(key);
- }
- /**
- * @dev Removes all the entries from a map. O(n).
- *
- * WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
- * function uncallable if the map grows to the point where clearing it consumes too much gas to fit in a block.
- */
- function clear(Bytes32ToBytes32Map storage map) internal {
- uint256 len = length(map);
- for (uint256 i = 0; i < len; ++i) {
- delete map._values[map._keys.at(i)];
- }
- map._keys.clear();
- }
- /**
- * @dev Returns true if the key is in the map. O(1).
- */
- function contains(Bytes32ToBytes32Map storage map, bytes32 key) internal view returns (bool) {
- return map._keys.contains(key);
- }
- /**
- * @dev Returns the number of key-value pairs in the map. O(1).
- */
- function length(Bytes32ToBytes32Map storage map) internal view returns (uint256) {
- return map._keys.length();
- }
- /**
- * @dev Returns the key-value pair stored at position `index` in the map. O(1).
- *
- * Note that there are no guarantees on the ordering of entries inside the
- * array, and it may change when more entries are added or removed.
- *
- * Requirements:
- *
- * - `index` must be strictly less than {length}.
- */
- function at(Bytes32ToBytes32Map storage map, uint256 index) internal view returns (bytes32 key, bytes32 value) {
- bytes32 atKey = map._keys.at(index);
- return (atKey, map._values[atKey]);
- }
- /**
- * @dev Tries to returns the value associated with `key`. O(1).
- * Does not revert if `key` is not in the map.
- */
- function tryGet(Bytes32ToBytes32Map storage map, bytes32 key) internal view returns (bool exists, bytes32 value) {
- bytes32 val = map._values[key];
- if (val == bytes32(0)) {
- return (contains(map, key), bytes32(0));
- } else {
- return (true, val);
- }
- }
- /**
- * @dev Returns the value associated with `key`. O(1).
- *
- * Requirements:
- *
- * - `key` must be in the map.
- */
- function get(Bytes32ToBytes32Map storage map, bytes32 key) internal view returns (bytes32) {
- bytes32 value = map._values[key];
- if (value == 0 && !contains(map, key)) {
- revert EnumerableMapNonexistentKey(key);
- }
- return value;
- }
- /**
- * @dev Return the an array containing all the keys
- *
- * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
- * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
- * this function has an unbounded cost, and using it as part of a state-changing function may render the function
- * uncallable if the map grows to a point where copying to memory consumes too much gas to fit in a block.
- */
- function keys(Bytes32ToBytes32Map storage map) internal view returns (bytes32[] memory) {
- return map._keys.values();
- }
- // UintToUintMap
- struct UintToUintMap {
- Bytes32ToBytes32Map _inner;
- }
- /**
- * @dev Adds a key-value pair to a map, or updates the value for an existing
- * key. O(1).
- *
- * Returns true if the key was added to the map, that is if it was not
- * already present.
- */
- function set(UintToUintMap storage map, uint256 key, uint256 value) internal returns (bool) {
- return set(map._inner, bytes32(key), bytes32(value));
- }
- /**
- * @dev Removes a value from a map. O(1).
- *
- * Returns true if the key was removed from the map, that is if it was present.
- */
- function remove(UintToUintMap storage map, uint256 key) internal returns (bool) {
- return remove(map._inner, bytes32(key));
- }
- /**
- * @dev Removes all the entries from a map. O(n).
- *
- * WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
- * function uncallable if the map grows to the point where clearing it consumes too much gas to fit in a block.
- */
- function clear(UintToUintMap storage map) internal {
- clear(map._inner);
- }
- /**
- * @dev Returns true if the key is in the map. O(1).
- */
- function contains(UintToUintMap storage map, uint256 key) internal view returns (bool) {
- return contains(map._inner, bytes32(key));
- }
- /**
- * @dev Returns the number of elements in the map. O(1).
- */
- function length(UintToUintMap storage map) internal view returns (uint256) {
- return length(map._inner);
- }
- /**
- * @dev Returns the element stored at position `index` in the map. O(1).
- * Note that there are no guarantees on the ordering of values inside the
- * array, and it may change when more values are added or removed.
- *
- * Requirements:
- *
- * - `index` must be strictly less than {length}.
- */
- function at(UintToUintMap storage map, uint256 index) internal view returns (uint256 key, uint256 value) {
- (bytes32 atKey, bytes32 val) = at(map._inner, index);
- return (uint256(atKey), uint256(val));
- }
- /**
- * @dev Tries to returns the value associated with `key`. O(1).
- * Does not revert if `key` is not in the map.
- */
- function tryGet(UintToUintMap storage map, uint256 key) internal view returns (bool exists, uint256 value) {
- (bool success, bytes32 val) = tryGet(map._inner, bytes32(key));
- return (success, uint256(val));
- }
- /**
- * @dev Returns the value associated with `key`. O(1).
- *
- * Requirements:
- *
- * - `key` must be in the map.
- */
- function get(UintToUintMap storage map, uint256 key) internal view returns (uint256) {
- return uint256(get(map._inner, bytes32(key)));
- }
- /**
- * @dev Return the an array containing all the keys
- *
- * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
- * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
- * this function has an unbounded cost, and using it as part of a state-changing function may render the function
- * uncallable if the map grows to a point where copying to memory consumes too much gas to fit in a block.
- */
- function keys(UintToUintMap storage map) internal view returns (uint256[] memory) {
- bytes32[] memory store = keys(map._inner);
- uint256[] memory result;
- assembly ("memory-safe") {
- result := store
- }
- return result;
- }
- // UintToAddressMap
- struct UintToAddressMap {
- Bytes32ToBytes32Map _inner;
- }
- /**
- * @dev Adds a key-value pair to a map, or updates the value for an existing
- * key. O(1).
- *
- * Returns true if the key was added to the map, that is if it was not
- * already present.
- */
- function set(UintToAddressMap storage map, uint256 key, address value) internal returns (bool) {
- return set(map._inner, bytes32(key), bytes32(uint256(uint160(value))));
- }
- /**
- * @dev Removes a value from a map. O(1).
- *
- * Returns true if the key was removed from the map, that is if it was present.
- */
- function remove(UintToAddressMap storage map, uint256 key) internal returns (bool) {
- return remove(map._inner, bytes32(key));
- }
- /**
- * @dev Removes all the entries from a map. O(n).
- *
- * WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
- * function uncallable if the map grows to the point where clearing it consumes too much gas to fit in a block.
- */
- function clear(UintToAddressMap storage map) internal {
- clear(map._inner);
- }
- /**
- * @dev Returns true if the key is in the map. O(1).
- */
- function contains(UintToAddressMap storage map, uint256 key) internal view returns (bool) {
- return contains(map._inner, bytes32(key));
- }
- /**
- * @dev Returns the number of elements in the map. O(1).
- */
- function length(UintToAddressMap storage map) internal view returns (uint256) {
- return length(map._inner);
- }
- /**
- * @dev Returns the element stored at position `index` in the map. O(1).
- * Note that there are no guarantees on the ordering of values inside the
- * array, and it may change when more values are added or removed.
- *
- * Requirements:
- *
- * - `index` must be strictly less than {length}.
- */
- function at(UintToAddressMap storage map, uint256 index) internal view returns (uint256 key, address value) {
- (bytes32 atKey, bytes32 val) = at(map._inner, index);
- return (uint256(atKey), address(uint160(uint256(val))));
- }
- /**
- * @dev Tries to returns the value associated with `key`. O(1).
- * Does not revert if `key` is not in the map.
- */
- function tryGet(UintToAddressMap storage map, uint256 key) internal view returns (bool exists, address value) {
- (bool success, bytes32 val) = tryGet(map._inner, bytes32(key));
- return (success, address(uint160(uint256(val))));
- }
- /**
- * @dev Returns the value associated with `key`. O(1).
- *
- * Requirements:
- *
- * - `key` must be in the map.
- */
- function get(UintToAddressMap storage map, uint256 key) internal view returns (address) {
- return address(uint160(uint256(get(map._inner, bytes32(key)))));
- }
- /**
- * @dev Return the an array containing all the keys
- *
- * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
- * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
- * this function has an unbounded cost, and using it as part of a state-changing function may render the function
- * uncallable if the map grows to a point where copying to memory consumes too much gas to fit in a block.
- */
- function keys(UintToAddressMap storage map) internal view returns (uint256[] memory) {
- bytes32[] memory store = keys(map._inner);
- uint256[] memory result;
- assembly ("memory-safe") {
- result := store
- }
- return result;
- }
- // UintToBytes32Map
- struct UintToBytes32Map {
- Bytes32ToBytes32Map _inner;
- }
- /**
- * @dev Adds a key-value pair to a map, or updates the value for an existing
- * key. O(1).
- *
- * Returns true if the key was added to the map, that is if it was not
- * already present.
- */
- function set(UintToBytes32Map storage map, uint256 key, bytes32 value) internal returns (bool) {
- return set(map._inner, bytes32(key), value);
- }
- /**
- * @dev Removes a value from a map. O(1).
- *
- * Returns true if the key was removed from the map, that is if it was present.
- */
- function remove(UintToBytes32Map storage map, uint256 key) internal returns (bool) {
- return remove(map._inner, bytes32(key));
- }
- /**
- * @dev Removes all the entries from a map. O(n).
- *
- * WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
- * function uncallable if the map grows to the point where clearing it consumes too much gas to fit in a block.
- */
- function clear(UintToBytes32Map storage map) internal {
- clear(map._inner);
- }
- /**
- * @dev Returns true if the key is in the map. O(1).
- */
- function contains(UintToBytes32Map storage map, uint256 key) internal view returns (bool) {
- return contains(map._inner, bytes32(key));
- }
- /**
- * @dev Returns the number of elements in the map. O(1).
- */
- function length(UintToBytes32Map storage map) internal view returns (uint256) {
- return length(map._inner);
- }
- /**
- * @dev Returns the element stored at position `index` in the map. O(1).
- * Note that there are no guarantees on the ordering of values inside the
- * array, and it may change when more values are added or removed.
- *
- * Requirements:
- *
- * - `index` must be strictly less than {length}.
- */
- function at(UintToBytes32Map storage map, uint256 index) internal view returns (uint256 key, bytes32 value) {
- (bytes32 atKey, bytes32 val) = at(map._inner, index);
- return (uint256(atKey), val);
- }
- /**
- * @dev Tries to returns the value associated with `key`. O(1).
- * Does not revert if `key` is not in the map.
- */
- function tryGet(UintToBytes32Map storage map, uint256 key) internal view returns (bool exists, bytes32 value) {
- (bool success, bytes32 val) = tryGet(map._inner, bytes32(key));
- return (success, val);
- }
- /**
- * @dev Returns the value associated with `key`. O(1).
- *
- * Requirements:
- *
- * - `key` must be in the map.
- */
- function get(UintToBytes32Map storage map, uint256 key) internal view returns (bytes32) {
- return get(map._inner, bytes32(key));
- }
- /**
- * @dev Return the an array containing all the keys
- *
- * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
- * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
- * this function has an unbounded cost, and using it as part of a state-changing function may render the function
- * uncallable if the map grows to a point where copying to memory consumes too much gas to fit in a block.
- */
- function keys(UintToBytes32Map storage map) internal view returns (uint256[] memory) {
- bytes32[] memory store = keys(map._inner);
- uint256[] memory result;
- assembly ("memory-safe") {
- result := store
- }
- return result;
- }
- // AddressToUintMap
- struct AddressToUintMap {
- Bytes32ToBytes32Map _inner;
- }
- /**
- * @dev Adds a key-value pair to a map, or updates the value for an existing
- * key. O(1).
- *
- * Returns true if the key was added to the map, that is if it was not
- * already present.
- */
- function set(AddressToUintMap storage map, address key, uint256 value) internal returns (bool) {
- return set(map._inner, bytes32(uint256(uint160(key))), bytes32(value));
- }
- /**
- * @dev Removes a value from a map. O(1).
- *
- * Returns true if the key was removed from the map, that is if it was present.
- */
- function remove(AddressToUintMap storage map, address key) internal returns (bool) {
- return remove(map._inner, bytes32(uint256(uint160(key))));
- }
- /**
- * @dev Removes all the entries from a map. O(n).
- *
- * WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
- * function uncallable if the map grows to the point where clearing it consumes too much gas to fit in a block.
- */
- function clear(AddressToUintMap storage map) internal {
- clear(map._inner);
- }
- /**
- * @dev Returns true if the key is in the map. O(1).
- */
- function contains(AddressToUintMap storage map, address key) internal view returns (bool) {
- return contains(map._inner, bytes32(uint256(uint160(key))));
- }
- /**
- * @dev Returns the number of elements in the map. O(1).
- */
- function length(AddressToUintMap storage map) internal view returns (uint256) {
- return length(map._inner);
- }
- /**
- * @dev Returns the element stored at position `index` in the map. O(1).
- * Note that there are no guarantees on the ordering of values inside the
- * array, and it may change when more values are added or removed.
- *
- * Requirements:
- *
- * - `index` must be strictly less than {length}.
- */
- function at(AddressToUintMap storage map, uint256 index) internal view returns (address key, uint256 value) {
- (bytes32 atKey, bytes32 val) = at(map._inner, index);
- return (address(uint160(uint256(atKey))), uint256(val));
- }
- /**
- * @dev Tries to returns the value associated with `key`. O(1).
- * Does not revert if `key` is not in the map.
- */
- function tryGet(AddressToUintMap storage map, address key) internal view returns (bool exists, uint256 value) {
- (bool success, bytes32 val) = tryGet(map._inner, bytes32(uint256(uint160(key))));
- return (success, uint256(val));
- }
- /**
- * @dev Returns the value associated with `key`. O(1).
- *
- * Requirements:
- *
- * - `key` must be in the map.
- */
- function get(AddressToUintMap storage map, address key) internal view returns (uint256) {
- return uint256(get(map._inner, bytes32(uint256(uint160(key)))));
- }
- /**
- * @dev Return the an array containing all the keys
- *
- * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
- * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
- * this function has an unbounded cost, and using it as part of a state-changing function may render the function
- * uncallable if the map grows to a point where copying to memory consumes too much gas to fit in a block.
- */
- function keys(AddressToUintMap storage map) internal view returns (address[] memory) {
- bytes32[] memory store = keys(map._inner);
- address[] memory result;
- assembly ("memory-safe") {
- result := store
- }
- return result;
- }
- // AddressToAddressMap
- struct AddressToAddressMap {
- Bytes32ToBytes32Map _inner;
- }
- /**
- * @dev Adds a key-value pair to a map, or updates the value for an existing
- * key. O(1).
- *
- * Returns true if the key was added to the map, that is if it was not
- * already present.
- */
- function set(AddressToAddressMap storage map, address key, address value) internal returns (bool) {
- return set(map._inner, bytes32(uint256(uint160(key))), bytes32(uint256(uint160(value))));
- }
- /**
- * @dev Removes a value from a map. O(1).
- *
- * Returns true if the key was removed from the map, that is if it was present.
- */
- function remove(AddressToAddressMap storage map, address key) internal returns (bool) {
- return remove(map._inner, bytes32(uint256(uint160(key))));
- }
- /**
- * @dev Removes all the entries from a map. O(n).
- *
- * WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
- * function uncallable if the map grows to the point where clearing it consumes too much gas to fit in a block.
- */
- function clear(AddressToAddressMap storage map) internal {
- clear(map._inner);
- }
- /**
- * @dev Returns true if the key is in the map. O(1).
- */
- function contains(AddressToAddressMap storage map, address key) internal view returns (bool) {
- return contains(map._inner, bytes32(uint256(uint160(key))));
- }
- /**
- * @dev Returns the number of elements in the map. O(1).
- */
- function length(AddressToAddressMap storage map) internal view returns (uint256) {
- return length(map._inner);
- }
- /**
- * @dev Returns the element stored at position `index` in the map. O(1).
- * Note that there are no guarantees on the ordering of values inside the
- * array, and it may change when more values are added or removed.
- *
- * Requirements:
- *
- * - `index` must be strictly less than {length}.
- */
- function at(AddressToAddressMap storage map, uint256 index) internal view returns (address key, address value) {
- (bytes32 atKey, bytes32 val) = at(map._inner, index);
- return (address(uint160(uint256(atKey))), address(uint160(uint256(val))));
- }
- /**
- * @dev Tries to returns the value associated with `key`. O(1).
- * Does not revert if `key` is not in the map.
- */
- function tryGet(AddressToAddressMap storage map, address key) internal view returns (bool exists, address value) {
- (bool success, bytes32 val) = tryGet(map._inner, bytes32(uint256(uint160(key))));
- return (success, address(uint160(uint256(val))));
- }
- /**
- * @dev Returns the value associated with `key`. O(1).
- *
- * Requirements:
- *
- * - `key` must be in the map.
- */
- function get(AddressToAddressMap storage map, address key) internal view returns (address) {
- return address(uint160(uint256(get(map._inner, bytes32(uint256(uint160(key)))))));
- }
- /**
- * @dev Return the an array containing all the keys
- *
- * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
- * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
- * this function has an unbounded cost, and using it as part of a state-changing function may render the function
- * uncallable if the map grows to a point where copying to memory consumes too much gas to fit in a block.
- */
- function keys(AddressToAddressMap storage map) internal view returns (address[] memory) {
- bytes32[] memory store = keys(map._inner);
- address[] memory result;
- assembly ("memory-safe") {
- result := store
- }
- return result;
- }
- // AddressToBytes32Map
- struct AddressToBytes32Map {
- Bytes32ToBytes32Map _inner;
- }
- /**
- * @dev Adds a key-value pair to a map, or updates the value for an existing
- * key. O(1).
- *
- * Returns true if the key was added to the map, that is if it was not
- * already present.
- */
- function set(AddressToBytes32Map storage map, address key, bytes32 value) internal returns (bool) {
- return set(map._inner, bytes32(uint256(uint160(key))), value);
- }
- /**
- * @dev Removes a value from a map. O(1).
- *
- * Returns true if the key was removed from the map, that is if it was present.
- */
- function remove(AddressToBytes32Map storage map, address key) internal returns (bool) {
- return remove(map._inner, bytes32(uint256(uint160(key))));
- }
- /**
- * @dev Removes all the entries from a map. O(n).
- *
- * WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
- * function uncallable if the map grows to the point where clearing it consumes too much gas to fit in a block.
- */
- function clear(AddressToBytes32Map storage map) internal {
- clear(map._inner);
- }
- /**
- * @dev Returns true if the key is in the map. O(1).
- */
- function contains(AddressToBytes32Map storage map, address key) internal view returns (bool) {
- return contains(map._inner, bytes32(uint256(uint160(key))));
- }
- /**
- * @dev Returns the number of elements in the map. O(1).
- */
- function length(AddressToBytes32Map storage map) internal view returns (uint256) {
- return length(map._inner);
- }
- /**
- * @dev Returns the element stored at position `index` in the map. O(1).
- * Note that there are no guarantees on the ordering of values inside the
- * array, and it may change when more values are added or removed.
- *
- * Requirements:
- *
- * - `index` must be strictly less than {length}.
- */
- function at(AddressToBytes32Map storage map, uint256 index) internal view returns (address key, bytes32 value) {
- (bytes32 atKey, bytes32 val) = at(map._inner, index);
- return (address(uint160(uint256(atKey))), val);
- }
- /**
- * @dev Tries to returns the value associated with `key`. O(1).
- * Does not revert if `key` is not in the map.
- */
- function tryGet(AddressToBytes32Map storage map, address key) internal view returns (bool exists, bytes32 value) {
- (bool success, bytes32 val) = tryGet(map._inner, bytes32(uint256(uint160(key))));
- return (success, val);
- }
- /**
- * @dev Returns the value associated with `key`. O(1).
- *
- * Requirements:
- *
- * - `key` must be in the map.
- */
- function get(AddressToBytes32Map storage map, address key) internal view returns (bytes32) {
- return get(map._inner, bytes32(uint256(uint160(key))));
- }
- /**
- * @dev Return the an array containing all the keys
- *
- * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
- * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
- * this function has an unbounded cost, and using it as part of a state-changing function may render the function
- * uncallable if the map grows to a point where copying to memory consumes too much gas to fit in a block.
- */
- function keys(AddressToBytes32Map storage map) internal view returns (address[] memory) {
- bytes32[] memory store = keys(map._inner);
- address[] memory result;
- assembly ("memory-safe") {
- result := store
- }
- return result;
- }
- // Bytes32ToUintMap
- struct Bytes32ToUintMap {
- Bytes32ToBytes32Map _inner;
- }
- /**
- * @dev Adds a key-value pair to a map, or updates the value for an existing
- * key. O(1).
- *
- * Returns true if the key was added to the map, that is if it was not
- * already present.
- */
- function set(Bytes32ToUintMap storage map, bytes32 key, uint256 value) internal returns (bool) {
- return set(map._inner, key, bytes32(value));
- }
- /**
- * @dev Removes a value from a map. O(1).
- *
- * Returns true if the key was removed from the map, that is if it was present.
- */
- function remove(Bytes32ToUintMap storage map, bytes32 key) internal returns (bool) {
- return remove(map._inner, key);
- }
- /**
- * @dev Removes all the entries from a map. O(n).
- *
- * WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
- * function uncallable if the map grows to the point where clearing it consumes too much gas to fit in a block.
- */
- function clear(Bytes32ToUintMap storage map) internal {
- clear(map._inner);
- }
- /**
- * @dev Returns true if the key is in the map. O(1).
- */
- function contains(Bytes32ToUintMap storage map, bytes32 key) internal view returns (bool) {
- return contains(map._inner, key);
- }
- /**
- * @dev Returns the number of elements in the map. O(1).
- */
- function length(Bytes32ToUintMap storage map) internal view returns (uint256) {
- return length(map._inner);
- }
- /**
- * @dev Returns the element stored at position `index` in the map. O(1).
- * Note that there are no guarantees on the ordering of values inside the
- * array, and it may change when more values are added or removed.
- *
- * Requirements:
- *
- * - `index` must be strictly less than {length}.
- */
- function at(Bytes32ToUintMap storage map, uint256 index) internal view returns (bytes32 key, uint256 value) {
- (bytes32 atKey, bytes32 val) = at(map._inner, index);
- return (atKey, uint256(val));
- }
- /**
- * @dev Tries to returns the value associated with `key`. O(1).
- * Does not revert if `key` is not in the map.
- */
- function tryGet(Bytes32ToUintMap storage map, bytes32 key) internal view returns (bool exists, uint256 value) {
- (bool success, bytes32 val) = tryGet(map._inner, key);
- return (success, uint256(val));
- }
- /**
- * @dev Returns the value associated with `key`. O(1).
- *
- * Requirements:
- *
- * - `key` must be in the map.
- */
- function get(Bytes32ToUintMap storage map, bytes32 key) internal view returns (uint256) {
- return uint256(get(map._inner, key));
- }
- /**
- * @dev Return the an array containing all the keys
- *
- * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
- * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
- * this function has an unbounded cost, and using it as part of a state-changing function may render the function
- * uncallable if the map grows to a point where copying to memory consumes too much gas to fit in a block.
- */
- function keys(Bytes32ToUintMap storage map) internal view returns (bytes32[] memory) {
- bytes32[] memory store = keys(map._inner);
- bytes32[] memory result;
- assembly ("memory-safe") {
- result := store
- }
- return result;
- }
- // Bytes32ToAddressMap
- struct Bytes32ToAddressMap {
- Bytes32ToBytes32Map _inner;
- }
- /**
- * @dev Adds a key-value pair to a map, or updates the value for an existing
- * key. O(1).
- *
- * Returns true if the key was added to the map, that is if it was not
- * already present.
- */
- function set(Bytes32ToAddressMap storage map, bytes32 key, address value) internal returns (bool) {
- return set(map._inner, key, bytes32(uint256(uint160(value))));
- }
- /**
- * @dev Removes a value from a map. O(1).
- *
- * Returns true if the key was removed from the map, that is if it was present.
- */
- function remove(Bytes32ToAddressMap storage map, bytes32 key) internal returns (bool) {
- return remove(map._inner, key);
- }
- /**
- * @dev Removes all the entries from a map. O(n).
- *
- * WARNING: Developers should keep in mind that this function has an unbounded cost and using it may render the
- * function uncallable if the map grows to the point where clearing it consumes too much gas to fit in a block.
- */
- function clear(Bytes32ToAddressMap storage map) internal {
- clear(map._inner);
- }
- /**
- * @dev Returns true if the key is in the map. O(1).
- */
- function contains(Bytes32ToAddressMap storage map, bytes32 key) internal view returns (bool) {
- return contains(map._inner, key);
- }
- /**
- * @dev Returns the number of elements in the map. O(1).
- */
- function length(Bytes32ToAddressMap storage map) internal view returns (uint256) {
- return length(map._inner);
- }
- /**
- * @dev Returns the element stored at position `index` in the map. O(1).
- * Note that there are no guarantees on the ordering of values inside the
- * array, and it may change when more values are added or removed.
- *
- * Requirements:
- *
- * - `index` must be strictly less than {length}.
- */
- function at(Bytes32ToAddressMap storage map, uint256 index) internal view returns (bytes32 key, address value) {
- (bytes32 atKey, bytes32 val) = at(map._inner, index);
- return (atKey, address(uint160(uint256(val))));
- }
- /**
- * @dev Tries to returns the value associated with `key`. O(1).
- * Does not revert if `key` is not in the map.
- */
- function tryGet(Bytes32ToAddressMap storage map, bytes32 key) internal view returns (bool exists, address value) {
- (bool success, bytes32 val) = tryGet(map._inner, key);
- return (success, address(uint160(uint256(val))));
- }
- /**
- * @dev Returns the value associated with `key`. O(1).
- *
- * Requirements:
- *
- * - `key` must be in the map.
- */
- function get(Bytes32ToAddressMap storage map, bytes32 key) internal view returns (address) {
- return address(uint160(uint256(get(map._inner, key))));
- }
- /**
- * @dev Return the an array containing all the keys
- *
- * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
- * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
- * this function has an unbounded cost, and using it as part of a state-changing function may render the function
- * uncallable if the map grows to a point where copying to memory consumes too much gas to fit in a block.
- */
- function keys(Bytes32ToAddressMap storage map) internal view returns (bytes32[] memory) {
- bytes32[] memory store = keys(map._inner);
- bytes32[] memory result;
- assembly ("memory-safe") {
- result := store
- }
- return result;
- }
- }
|