123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792 |
- // SPDX-License-Identifier: MIT
- // OpenZeppelin Contracts (last updated v5.4.0-rc.0) (utils/structs/EnumerableSet.sol)
- // This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.
- pragma solidity ^0.8.20;
- import {Arrays} from "../Arrays.sol";
- import {Math} from "../math/Math.sol";
- /**
- * @dev Library for managing
- * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
- * types.
- *
- * Sets have the following properties:
- *
- * - 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 {
- * // Add the library methods
- * using EnumerableSet for EnumerableSet.AddressSet;
- *
- * // Declare a set state variable
- * EnumerableSet.AddressSet private mySet;
- * }
- * ```
- *
- * The following types are supported:
- *
- * - `bytes32` (`Bytes32Set`) since v3.3.0
- * - `address` (`AddressSet`) since v3.3.0
- * - `uint256` (`UintSet`) since v3.3.0
- * - `string` (`StringSet`) since v5.4.0
- * - `bytes` (`BytesSet`) since v5.4.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 EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
- * array of EnumerableSet.
- * ====
- */
- library EnumerableSet {
- // To implement this library for multiple types with as little code
- // repetition as possible, we write it in terms of a generic Set type with
- // bytes32 values.
- // The Set implementation uses private functions, and user-facing
- // implementations (such as AddressSet) are just wrappers around the
- // underlying Set.
- // This means that we can only create new EnumerableSets for types that fit
- // in bytes32.
- struct Set {
- // Storage of set values
- bytes32[] _values;
- // Position is the index of the value in the `values` array plus 1.
- // Position 0 is used to mean a value is not in the set.
- mapping(bytes32 value => uint256) _positions;
- }
- /**
- * @dev Add a value to a set. O(1).
- *
- * Returns true if the value was added to the set, that is if it was not
- * already present.
- */
- function _add(Set storage set, bytes32 value) private returns (bool) {
- if (!_contains(set, value)) {
- set._values.push(value);
- // The value is stored at length-1, but we add 1 to all indexes
- // and use 0 as a sentinel value
- set._positions[value] = set._values.length;
- return true;
- } else {
- return false;
- }
- }
- /**
- * @dev Removes a value from a set. O(1).
- *
- * Returns true if the value was removed from the set, that is if it was
- * present.
- */
- function _remove(Set storage set, bytes32 value) private returns (bool) {
- // We cache the value's position to prevent multiple reads from the same storage slot
- uint256 position = set._positions[value];
- if (position != 0) {
- // Equivalent to contains(set, value)
- // To delete an element from the _values array in O(1), we swap the element to delete with the last one in
- // the array, and then remove the last element (sometimes called as 'swap and pop').
- // This modifies the order of the array, as noted in {at}.
- uint256 valueIndex = position - 1;
- uint256 lastIndex = set._values.length - 1;
- if (valueIndex != lastIndex) {
- bytes32 lastValue = set._values[lastIndex];
- // Move the lastValue to the index where the value to delete is
- set._values[valueIndex] = lastValue;
- // Update the tracked position of the lastValue (that was just moved)
- set._positions[lastValue] = position;
- }
- // Delete the slot where the moved value was stored
- set._values.pop();
- // Delete the tracked position for the deleted slot
- delete set._positions[value];
- return true;
- } else {
- return false;
- }
- }
- /**
- * @dev Removes all the values from a set. O(n).
- *
- * WARNING: This function has an unbounded cost that scales with set size. Developers should keep in mind that
- * 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).
- */
- function _contains(Set storage set, bytes32 value) private view returns (bool) {
- return set._positions[value] != 0;
- }
- /**
- * @dev Returns the number of values on the set. O(1).
- */
- function _length(Set storage set) private view returns (uint256) {
- return set._values.length;
- }
- /**
- * @dev Returns the value stored at position `index` in the set. 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(Set storage set, uint256 index) private view returns (bytes32) {
- return set._values[index];
- }
- /**
- * @dev Return the entire set in an array
- *
- * 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 set grows to a point where copying to memory consumes too much gas to fit in a block.
- */
- function _values(Set storage set) private view returns (bytes32[] memory) {
- return set._values;
- }
- /**
- * @dev Return a slice of the set in an array
- *
- * 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 set grows to a point where copying to memory consumes too much gas to fit in a block.
- */
- function _values(Set storage set, uint256 start, uint256 end) private view returns (bytes32[] memory) {
- unchecked {
- end = Math.min(end, _length(set));
- start = Math.min(start, end);
- uint256 len = end - start;
- bytes32[] memory result = new bytes32[](len);
- for (uint256 i = 0; i < len; ++i) {
- result[i] = Arrays.unsafeAccess(set._values, start + i).value;
- }
- return result;
- }
- }
- // Bytes32Set
- struct Bytes32Set {
- Set _inner;
- }
- /**
- * @dev Add a value to a set. O(1).
- *
- * Returns true if the value was added to the set, that is if it was not
- * already present.
- */
- function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
- return _add(set._inner, value);
- }
- /**
- * @dev Removes a value from a set. O(1).
- *
- * Returns true if the value was removed from the set, that is if it was
- * present.
- */
- function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
- return _remove(set._inner, 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(Bytes32Set storage set) internal {
- _clear(set._inner);
- }
- /**
- * @dev Returns true if the value is in the set. O(1).
- */
- function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
- return _contains(set._inner, value);
- }
- /**
- * @dev Returns the number of values in the set. O(1).
- */
- function length(Bytes32Set storage set) internal view returns (uint256) {
- return _length(set._inner);
- }
- /**
- * @dev Returns the value stored at position `index` in the set. 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(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
- return _at(set._inner, index);
- }
- /**
- * @dev Return the entire set in an array
- *
- * 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 set grows to a point where copying to memory consumes too much gas to fit in a block.
- */
- function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
- bytes32[] memory store = _values(set._inner);
- bytes32[] memory result;
- assembly ("memory-safe") {
- result := store
- }
- return result;
- }
- /**
- * @dev Return a slice of the set in an array
- *
- * 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 set grows to a point where copying to memory consumes too much gas to fit in a block.
- */
- function values(Bytes32Set storage set, uint256 start, uint256 end) internal view returns (bytes32[] memory) {
- bytes32[] memory store = _values(set._inner, start, end);
- bytes32[] memory result;
- assembly ("memory-safe") {
- result := store
- }
- return result;
- }
- // AddressSet
- struct AddressSet {
- Set _inner;
- }
- /**
- * @dev Add a value to a set. O(1).
- *
- * Returns true if the value was added to the set, that is if it was not
- * already present.
- */
- function add(AddressSet storage set, address value) internal returns (bool) {
- return _add(set._inner, bytes32(uint256(uint160(value))));
- }
- /**
- * @dev Removes a value from a set. O(1).
- *
- * Returns true if the value was removed from the set, that is if it was
- * present.
- */
- function remove(AddressSet storage set, address value) internal returns (bool) {
- return _remove(set._inner, bytes32(uint256(uint160(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(AddressSet storage set) internal {
- _clear(set._inner);
- }
- /**
- * @dev Returns true if the value is in the set. O(1).
- */
- function contains(AddressSet storage set, address value) internal view returns (bool) {
- return _contains(set._inner, bytes32(uint256(uint160(value))));
- }
- /**
- * @dev Returns the number of values in the set. O(1).
- */
- function length(AddressSet storage set) internal view returns (uint256) {
- return _length(set._inner);
- }
- /**
- * @dev Returns the value stored at position `index` in the set. 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(AddressSet storage set, uint256 index) internal view returns (address) {
- return address(uint160(uint256(_at(set._inner, index))));
- }
- /**
- * @dev Return the entire set in an array
- *
- * 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 set grows to a point where copying to memory consumes too much gas to fit in a block.
- */
- function values(AddressSet storage set) internal view returns (address[] memory) {
- bytes32[] memory store = _values(set._inner);
- address[] memory result;
- assembly ("memory-safe") {
- result := store
- }
- return result;
- }
- /**
- * @dev Return a slice of the set in an array
- *
- * 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 set grows to a point where copying to memory consumes too much gas to fit in a block.
- */
- function values(AddressSet storage set, uint256 start, uint256 end) internal view returns (address[] memory) {
- bytes32[] memory store = _values(set._inner, start, end);
- address[] memory result;
- assembly ("memory-safe") {
- result := store
- }
- return result;
- }
- // UintSet
- struct UintSet {
- Set _inner;
- }
- /**
- * @dev Add a value to a set. O(1).
- *
- * Returns true if the value was added to the set, that is if it was not
- * already present.
- */
- function add(UintSet storage set, uint256 value) internal returns (bool) {
- return _add(set._inner, bytes32(value));
- }
- /**
- * @dev Removes a value from a set. O(1).
- *
- * Returns true if the value was removed from the set, that is if it was
- * present.
- */
- function remove(UintSet storage set, uint256 value) internal returns (bool) {
- return _remove(set._inner, bytes32(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(UintSet storage set) internal {
- _clear(set._inner);
- }
- /**
- * @dev Returns true if the value is in the set. O(1).
- */
- function contains(UintSet storage set, uint256 value) internal view returns (bool) {
- return _contains(set._inner, bytes32(value));
- }
- /**
- * @dev Returns the number of values in the set. O(1).
- */
- function length(UintSet storage set) internal view returns (uint256) {
- return _length(set._inner);
- }
- /**
- * @dev Returns the value stored at position `index` in the set. 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(UintSet storage set, uint256 index) internal view returns (uint256) {
- return uint256(_at(set._inner, index));
- }
- /**
- * @dev Return the entire set in an array
- *
- * 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 set grows to a point where copying to memory consumes too much gas to fit in a block.
- */
- function values(UintSet storage set) internal view returns (uint256[] memory) {
- bytes32[] memory store = _values(set._inner);
- uint256[] memory result;
- assembly ("memory-safe") {
- result := store
- }
- return result;
- }
- /**
- * @dev Return a slice of the set in an array
- *
- * 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 set grows to a point where copying to memory consumes too much gas to fit in a block.
- */
- function values(UintSet storage set, uint256 start, uint256 end) internal view returns (uint256[] memory) {
- bytes32[] memory store = _values(set._inner, start, end);
- uint256[] memory result;
- assembly ("memory-safe") {
- result := store
- }
- return result;
- }
- struct StringSet {
- // Storage of set values
- string[] _values;
- // Position is the index of the value in the `values` array plus 1.
- // Position 0 is used to mean a value is not in the set.
- mapping(string value => uint256) _positions;
- }
- /**
- * @dev Add a value to a set. O(1).
- *
- * Returns true if the value was added to the set, that is if it was not
- * already present.
- */
- function add(StringSet storage set, string memory value) internal returns (bool) {
- if (!contains(set, value)) {
- set._values.push(value);
- // The value is stored at length-1, but we add 1 to all indexes
- // and use 0 as a sentinel value
- set._positions[value] = set._values.length;
- return true;
- } else {
- return false;
- }
- }
- /**
- * @dev Removes a value from a set. O(1).
- *
- * Returns true if the value was removed from the set, that is if it was
- * present.
- */
- function remove(StringSet storage set, string memory value) internal returns (bool) {
- // We cache the value's position to prevent multiple reads from the same storage slot
- uint256 position = set._positions[value];
- if (position != 0) {
- // Equivalent to contains(set, value)
- // To delete an element from the _values array in O(1), we swap the element to delete with the last one in
- // the array, and then remove the last element (sometimes called as 'swap and pop').
- // This modifies the order of the array, as noted in {at}.
- uint256 valueIndex = position - 1;
- uint256 lastIndex = set._values.length - 1;
- if (valueIndex != lastIndex) {
- string memory lastValue = set._values[lastIndex];
- // Move the lastValue to the index where the value to delete is
- set._values[valueIndex] = lastValue;
- // Update the tracked position of the lastValue (that was just moved)
- set._positions[lastValue] = position;
- }
- // Delete the slot where the moved value was stored
- set._values.pop();
- // Delete the tracked position for the deleted slot
- delete set._positions[value];
- return true;
- } else {
- return false;
- }
- }
- /**
- * @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(StringSet storage set) internal {
- 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).
- */
- function contains(StringSet storage set, string memory value) internal view returns (bool) {
- return set._positions[value] != 0;
- }
- /**
- * @dev Returns the number of values on the set. O(1).
- */
- function length(StringSet storage set) internal view returns (uint256) {
- return set._values.length;
- }
- /**
- * @dev Returns the value stored at position `index` in the set. 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(StringSet storage set, uint256 index) internal view returns (string memory) {
- return set._values[index];
- }
- /**
- * @dev Return the entire set in an array
- *
- * 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 set grows to a point where copying to memory consumes too much gas to fit in a block.
- */
- function values(StringSet storage set) internal view returns (string[] memory) {
- return set._values;
- }
- /**
- * @dev Return a slice of the set in an array
- *
- * 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 set grows to a point where copying to memory consumes too much gas to fit in a block.
- */
- function values(StringSet storage set, uint256 start, uint256 end) internal view returns (string[] memory) {
- unchecked {
- end = Math.min(end, length(set));
- start = Math.min(start, end);
- uint256 len = end - start;
- string[] memory result = new string[](len);
- for (uint256 i = 0; i < len; ++i) {
- result[i] = Arrays.unsafeAccess(set._values, start + i).value;
- }
- return result;
- }
- }
- struct BytesSet {
- // Storage of set values
- bytes[] _values;
- // Position is the index of the value in the `values` array plus 1.
- // Position 0 is used to mean a value is not in the set.
- mapping(bytes value => uint256) _positions;
- }
- /**
- * @dev Add a value to a set. O(1).
- *
- * Returns true if the value was added to the set, that is if it was not
- * already present.
- */
- function add(BytesSet storage set, bytes memory value) internal returns (bool) {
- if (!contains(set, value)) {
- set._values.push(value);
- // The value is stored at length-1, but we add 1 to all indexes
- // and use 0 as a sentinel value
- set._positions[value] = set._values.length;
- return true;
- } else {
- return false;
- }
- }
- /**
- * @dev Removes a value from a set. O(1).
- *
- * Returns true if the value was removed from the set, that is if it was
- * present.
- */
- function remove(BytesSet storage set, bytes memory value) internal returns (bool) {
- // We cache the value's position to prevent multiple reads from the same storage slot
- uint256 position = set._positions[value];
- if (position != 0) {
- // Equivalent to contains(set, value)
- // To delete an element from the _values array in O(1), we swap the element to delete with the last one in
- // the array, and then remove the last element (sometimes called as 'swap and pop').
- // This modifies the order of the array, as noted in {at}.
- uint256 valueIndex = position - 1;
- uint256 lastIndex = set._values.length - 1;
- if (valueIndex != lastIndex) {
- bytes memory lastValue = set._values[lastIndex];
- // Move the lastValue to the index where the value to delete is
- set._values[valueIndex] = lastValue;
- // Update the tracked position of the lastValue (that was just moved)
- set._positions[lastValue] = position;
- }
- // Delete the slot where the moved value was stored
- set._values.pop();
- // Delete the tracked position for the deleted slot
- delete set._positions[value];
- return true;
- } else {
- return false;
- }
- }
- /**
- * @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(BytesSet storage set) internal {
- 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).
- */
- function contains(BytesSet storage set, bytes memory value) internal view returns (bool) {
- return set._positions[value] != 0;
- }
- /**
- * @dev Returns the number of values on the set. O(1).
- */
- function length(BytesSet storage set) internal view returns (uint256) {
- return set._values.length;
- }
- /**
- * @dev Returns the value stored at position `index` in the set. 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(BytesSet storage set, uint256 index) internal view returns (bytes memory) {
- return set._values[index];
- }
- /**
- * @dev Return the entire set in an array
- *
- * 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 set grows to a point where copying to memory consumes too much gas to fit in a block.
- */
- function values(BytesSet storage set) internal view returns (bytes[] memory) {
- return set._values;
- }
- /**
- * @dev Return a slice of the set in an array
- *
- * 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 set grows to a point where copying to memory consumes too much gas to fit in a block.
- */
- function values(BytesSet storage set, uint256 start, uint256 end) internal view returns (bytes[] memory) {
- unchecked {
- end = Math.min(end, length(set));
- start = Math.min(start, end);
- uint256 len = end - start;
- bytes[] memory result = new bytes[](len);
- for (uint256 i = 0; i < len; ++i) {
- result[i] = Arrays.unsafeAccess(set._values, start + i).value;
- }
- return result;
- }
- }
- }
|