Merge branch 'master' into next-v5.0
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// OpenZeppelin Contracts (last updated v4.8.0) (utils/Checkpoints.sol)
|
||||
// OpenZeppelin Contracts (last updated v4.8.1) (utils/Checkpoints.sol)
|
||||
// This file was procedurally generated from scripts/generate/templates/Checkpoints.js.
|
||||
|
||||
pragma solidity ^0.8.0;
|
||||
@ -69,13 +69,6 @@ library Checkpoints {
|
||||
return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns checkpoint at given position.
|
||||
*/
|
||||
function getAtPosition(History storage self, uint32 pos) internal view returns (Checkpoint memory) {
|
||||
return self._checkpoints[pos];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Pushes a value onto a History so that it is stored as the checkpoint for the current block.
|
||||
*
|
||||
@ -130,6 +123,13 @@ library Checkpoints {
|
||||
return self._checkpoints.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns checkpoint at given position.
|
||||
*/
|
||||
function at(History storage self, uint32 pos) internal view returns (Checkpoint memory) {
|
||||
return self._checkpoints[pos];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Pushes a (`key`, `value`) pair into an ordered list of checkpoints, either by inserting a new checkpoint,
|
||||
* or by updating the last one.
|
||||
@ -158,7 +158,7 @@ library Checkpoints {
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Return the index of the oldest checkpoint whose key is greater than the search key, or `high` if there is none.
|
||||
* @dev Return the index of the last (most recent) checkpoint with key lower or equal than the search key, or `high` if there is none.
|
||||
* `low` and `high` define a section where to do the search, with inclusive `low` and exclusive `high`.
|
||||
*
|
||||
* WARNING: `high` should not be greater than the array's length.
|
||||
@ -181,7 +181,7 @@ library Checkpoints {
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Return the index of the oldest checkpoint whose key is greater or equal than the search key, or `high` if there is none.
|
||||
* @dev Return the index of the first (oldest) checkpoint with key is greater or equal than the search key, or `high` if there is none.
|
||||
* `low` and `high` define a section where to do the search, with inclusive `low` and exclusive `high`.
|
||||
*
|
||||
* WARNING: `high` should not be greater than the array's length.
|
||||
@ -232,7 +232,7 @@ library Checkpoints {
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the value in the oldest checkpoint with key greater or equal than the search key, or zero if there is none.
|
||||
* @dev Returns the value in the first (oldest) checkpoint with key greater or equal than the search key, or zero if there is none.
|
||||
*/
|
||||
function lowerLookup(Trace224 storage self, uint32 key) internal view returns (uint224) {
|
||||
uint256 len = self._checkpoints.length;
|
||||
@ -241,7 +241,7 @@ library Checkpoints {
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the value in the most recent checkpoint with key lower or equal than the search key.
|
||||
* @dev Returns the value in the last (most recent) checkpoint with key lower or equal than the search key, or zero if there is none.
|
||||
*/
|
||||
function upperLookup(Trace224 storage self, uint32 key) internal view returns (uint224) {
|
||||
uint256 len = self._checkpoints.length;
|
||||
@ -249,6 +249,31 @@ library Checkpoints {
|
||||
return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the value in the last (most recent) checkpoint with key lower or equal than the search key, or zero if there is none.
|
||||
*
|
||||
* NOTE: This is a variant of {upperLookup} that is optimised to find "recent" checkpoint (checkpoints with high keys).
|
||||
*/
|
||||
function upperLookupRecent(Trace224 storage self, uint32 key) internal view returns (uint224) {
|
||||
uint256 len = self._checkpoints.length;
|
||||
|
||||
uint256 low = 0;
|
||||
uint256 high = len;
|
||||
|
||||
if (len > 5) {
|
||||
uint256 mid = len - Math.sqrt(len);
|
||||
if (key < _unsafeAccess(self._checkpoints, mid)._key) {
|
||||
high = mid;
|
||||
} else {
|
||||
low = mid + 1;
|
||||
}
|
||||
}
|
||||
|
||||
uint256 pos = _upperBinaryLookup(self._checkpoints, key, low, high);
|
||||
|
||||
return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the value in the most recent checkpoint, or zero if there are no checkpoints.
|
||||
*/
|
||||
@ -278,6 +303,13 @@ library Checkpoints {
|
||||
return self._checkpoints.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns checkpoint at given position.
|
||||
*/
|
||||
function at(Trace224 storage self, uint32 pos) internal view returns (Checkpoint224 memory) {
|
||||
return self._checkpoints[pos];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Pushes a (`key`, `value`) pair into an ordered list of checkpoints, either by inserting a new checkpoint,
|
||||
* or by updating the last one.
|
||||
@ -306,7 +338,7 @@ library Checkpoints {
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Return the index of the oldest checkpoint whose key is greater than the search key, or `high` if there is none.
|
||||
* @dev Return the index of the last (most recent) checkpoint with key lower or equal than the search key, or `high` if there is none.
|
||||
* `low` and `high` define a section where to do the search, with inclusive `low` and exclusive `high`.
|
||||
*
|
||||
* WARNING: `high` should not be greater than the array's length.
|
||||
@ -329,7 +361,7 @@ library Checkpoints {
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Return the index of the oldest checkpoint whose key is greater or equal than the search key, or `high` if there is none.
|
||||
* @dev Return the index of the first (oldest) checkpoint with key is greater or equal than the search key, or `high` if there is none.
|
||||
* `low` and `high` define a section where to do the search, with inclusive `low` and exclusive `high`.
|
||||
*
|
||||
* WARNING: `high` should not be greater than the array's length.
|
||||
@ -383,7 +415,7 @@ library Checkpoints {
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the value in the oldest checkpoint with key greater or equal than the search key, or zero if there is none.
|
||||
* @dev Returns the value in the first (oldest) checkpoint with key greater or equal than the search key, or zero if there is none.
|
||||
*/
|
||||
function lowerLookup(Trace160 storage self, uint96 key) internal view returns (uint160) {
|
||||
uint256 len = self._checkpoints.length;
|
||||
@ -392,7 +424,7 @@ library Checkpoints {
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the value in the most recent checkpoint with key lower or equal than the search key.
|
||||
* @dev Returns the value in the last (most recent) checkpoint with key lower or equal than the search key, or zero if there is none.
|
||||
*/
|
||||
function upperLookup(Trace160 storage self, uint96 key) internal view returns (uint160) {
|
||||
uint256 len = self._checkpoints.length;
|
||||
@ -400,6 +432,31 @@ library Checkpoints {
|
||||
return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the value in the last (most recent) checkpoint with key lower or equal than the search key, or zero if there is none.
|
||||
*
|
||||
* NOTE: This is a variant of {upperLookup} that is optimised to find "recent" checkpoint (checkpoints with high keys).
|
||||
*/
|
||||
function upperLookupRecent(Trace160 storage self, uint96 key) internal view returns (uint160) {
|
||||
uint256 len = self._checkpoints.length;
|
||||
|
||||
uint256 low = 0;
|
||||
uint256 high = len;
|
||||
|
||||
if (len > 5) {
|
||||
uint256 mid = len - Math.sqrt(len);
|
||||
if (key < _unsafeAccess(self._checkpoints, mid)._key) {
|
||||
high = mid;
|
||||
} else {
|
||||
low = mid + 1;
|
||||
}
|
||||
}
|
||||
|
||||
uint256 pos = _upperBinaryLookup(self._checkpoints, key, low, high);
|
||||
|
||||
return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns the value in the most recent checkpoint, or zero if there are no checkpoints.
|
||||
*/
|
||||
@ -429,6 +486,13 @@ library Checkpoints {
|
||||
return self._checkpoints.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns checkpoint at given position.
|
||||
*/
|
||||
function at(Trace160 storage self, uint32 pos) internal view returns (Checkpoint160 memory) {
|
||||
return self._checkpoints[pos];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Pushes a (`key`, `value`) pair into an ordered list of checkpoints, either by inserting a new checkpoint,
|
||||
* or by updating the last one.
|
||||
@ -457,7 +521,7 @@ library Checkpoints {
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Return the index of the oldest checkpoint whose key is greater than the search key, or `high` if there is none.
|
||||
* @dev Return the index of the last (most recent) checkpoint with key lower or equal than the search key, or `high` if there is none.
|
||||
* `low` and `high` define a section where to do the search, with inclusive `low` and exclusive `high`.
|
||||
*
|
||||
* WARNING: `high` should not be greater than the array's length.
|
||||
@ -480,7 +544,7 @@ library Checkpoints {
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Return the index of the oldest checkpoint whose key is greater or equal than the search key, or `high` if there is none.
|
||||
* @dev Return the index of the first (oldest) checkpoint with key is greater or equal than the search key, or `high` if there is none.
|
||||
* `low` and `high` define a section where to do the search, with inclusive `low` and exclusive `high`.
|
||||
*
|
||||
* WARNING: `high` should not be greater than the array's length.
|
||||
|
||||
Reference in New Issue
Block a user