Update docs
This commit is contained in:
@ -346,7 +346,7 @@ function unsafeMemoryAccess(${type}[] memory arr, uint256 pos) internal pure ret
|
||||
|
||||
const unsafeSetLength = type => `\
|
||||
/**
|
||||
* @dev Helper to set the length of an dynamic array. Directly writing to \`.length\` is forbidden.
|
||||
* @dev Helper to set the length of a dynamic array. Directly writing to \`.length\` is forbidden.
|
||||
*
|
||||
* WARNING: this does not clear elements if length is reduced, of initialize elements if length is increased.
|
||||
*/
|
||||
|
||||
@ -119,7 +119,7 @@ function latestCheckpoint(${opts.historyTypeName} storage self) internal view re
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the number of checkpoint.
|
||||
* @dev Returns the number of checkpoints.
|
||||
*/
|
||||
function length(${opts.historyTypeName} storage self) internal view returns (uint256) {
|
||||
return self.${opts.checkpointFieldName}.length;
|
||||
|
||||
@ -14,7 +14,7 @@ import {Checkpoints} from "@openzeppelin/contracts/utils/structs/Checkpoints.sol
|
||||
const template = opts => `\
|
||||
using Checkpoints for Checkpoints.${opts.historyTypeName};
|
||||
|
||||
// Maximum gap between keys used during the fuzzing tests: the \`_prepareKeys\` function with make sure that
|
||||
// Maximum gap between keys used during the fuzzing tests: the \`_prepareKeys\` function will make sure that
|
||||
// key#n+1 is in the [key#n, key#n + _KEY_MAX_GAP] range.
|
||||
uint8 internal constant _KEY_MAX_GAP = 64;
|
||||
|
||||
@ -36,7 +36,7 @@ function _prepareKeys(${opts.keyTypeName}[] memory keys, ${opts.keyTypeName} max
|
||||
}
|
||||
}
|
||||
|
||||
function _assertLatestCheckpoint(bool exist, ${opts.keyTypeName} key, ${opts.valueTypeName} value) internal {
|
||||
function _assertLatestCheckpoint(bool exist, ${opts.keyTypeName} key, ${opts.valueTypeName} value) internal view {
|
||||
(bool _exist, ${opts.keyTypeName} _key, ${opts.valueTypeName} _value) = _ckpts.latestCheckpoint();
|
||||
assertEq(_exist, exist);
|
||||
assertEq(_key, key);
|
||||
|
||||
@ -17,6 +17,7 @@ import {EnumerableSet} from "./EnumerableSet.sol";
|
||||
* - 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 {
|
||||
@ -91,6 +92,20 @@ function remove(Bytes32ToBytes32Map storage map, bytes32 key) internal returns (
|
||||
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).
|
||||
*/
|
||||
@ -188,6 +203,16 @@ function remove(${name} storage map, ${keyType} key) internal returns (bool) {
|
||||
return remove(map._inner, ${toBytes32(keyType, '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(${name} storage map) internal {
|
||||
clear(map._inner);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns true if the key is in the map. O(1).
|
||||
*/
|
||||
|
||||
@ -5,6 +5,8 @@ const { TYPES } = require('./EnumerableSet.opts');
|
||||
const header = `\
|
||||
pragma solidity ^0.8.20;
|
||||
|
||||
import {Arrays} from "../Arrays.sol";
|
||||
|
||||
/**
|
||||
* @dev Library for managing
|
||||
* https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
|
||||
@ -15,6 +17,7 @@ pragma solidity ^0.8.20;
|
||||
* - Elements are added, removed, and checked for existence in constant time
|
||||
* (O(1)).
|
||||
* - Elements are enumerated in O(n). No guarantees are made on the ordering.
|
||||
* - Set can be cleared (all elements removed) in O(n).
|
||||
*
|
||||
* \`\`\`solidity
|
||||
* contract Example {
|
||||
@ -117,6 +120,20 @@ function _remove(Set storage set, bytes32 value) private returns (bool) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Removes all the values from a set. 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 set grows to the point where clearing it consumes too much gas to fit in a block.
|
||||
*/
|
||||
function _clear(Set storage set) private {
|
||||
uint256 len = _length(set);
|
||||
for (uint256 i = 0; i < len; ++i) {
|
||||
delete set._positions[set._values[i]];
|
||||
}
|
||||
Arrays.unsafeSetLength(set._values, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns true if the value is in the set. O(1).
|
||||
*/
|
||||
@ -185,6 +202,16 @@ function remove(${name} storage set, ${type} value) internal returns (bool) {
|
||||
return _remove(set._inner, ${toBytes32(type, 'value')});
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Removes all the values from a set. 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 set grows to the point where clearing it consumes too much gas to fit in a block.
|
||||
*/
|
||||
function clear(${name} storage set) internal {
|
||||
_clear(set._inner);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns true if the value is in the set. O(1).
|
||||
*/
|
||||
|
||||
@ -20,7 +20,7 @@ pragma solidity ^0.8.20;
|
||||
* using SlotDerivation for bytes32;
|
||||
*
|
||||
* // Declare a namespace
|
||||
* string private constant _NAMESPACE = "<namespace>" // eg. OpenZeppelin.Slot
|
||||
* string private constant _NAMESPACE = "<namespace>"; // eg. OpenZeppelin.Slot
|
||||
*
|
||||
* function setValueInNamespace(uint256 key, address newValue) internal {
|
||||
* _NAMESPACE.erc7201Slot().deriveMapping(key).getAddressSlot().value = newValue;
|
||||
|
||||
@ -45,7 +45,7 @@ function _assertDeriveArray(uint256 length, uint256 offset) public {
|
||||
const mapping = ({ type, name }) => `\
|
||||
mapping(${type} => bytes) private _${type}Mapping;
|
||||
|
||||
function testSymbolicDeriveMapping${name}(${type} key) public {
|
||||
function testSymbolicDeriveMapping${name}(${type} key) public view {
|
||||
bytes32 baseSlot;
|
||||
assembly {
|
||||
baseSlot := _${type}Mapping.slot
|
||||
@ -76,15 +76,15 @@ function testSymbolicDeriveMapping${name}Dirty(bytes32 dirtyKey) public {
|
||||
const boundedMapping = ({ type, name }) => `\
|
||||
mapping(${type} => bytes) private _${type}Mapping;
|
||||
|
||||
function testDeriveMapping${name}(${type} memory key) public {
|
||||
function testDeriveMapping${name}(${type} memory key) public view {
|
||||
_assertDeriveMapping${name}(key);
|
||||
}
|
||||
|
||||
function symbolicDeriveMapping${name}() public {
|
||||
function symbolicDeriveMapping${name}() public view {
|
||||
_assertDeriveMapping${name}(svm.create${name}(256, "DeriveMapping${name}Input"));
|
||||
}
|
||||
|
||||
function _assertDeriveMapping${name}(${type} memory key) internal {
|
||||
function _assertDeriveMapping${name}(${type} memory key) internal view {
|
||||
bytes32 baseSlot;
|
||||
assembly {
|
||||
baseSlot := _${type}Mapping.slot
|
||||
|
||||
@ -34,7 +34,7 @@ pragma solidity ^0.8.24;
|
||||
|
||||
const udvt = ({ type, name }) => `\
|
||||
/**
|
||||
* @dev UDVT that represent a slot holding a ${type}.
|
||||
* @dev UDVT that represents a slot holding ${type == 'address' ? 'an' : 'a'} ${type}.
|
||||
*/
|
||||
type ${name}Slot is bytes32;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user