Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Apply trivial PR suggestions
  • Loading branch information
ernestognw committed Mar 25, 2024
commit f160bc7d7e36354c32687bb288c9d5ecb47b0f83
2 changes: 1 addition & 1 deletion .changeset/cold-cheetahs-check.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
'openzeppelin-solidity': minor
---

`CircularBuffer`: add a datastructure that stored the last N values pushed to it.
`CircularBuffer`: Add a data structure that stores the last `N` values pushed to it.
3 changes: 3 additions & 0 deletions contracts/utils/Arrays.sol
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ library Arrays {
* WARNING: this does not clear elements if length is reduced, of initialize elements if length is increased.
*/
function unsafeSetLength(address[] storage array, uint256 len) internal {
/// @solidity memory-safe-assembly
assembly {
sstore(array.slot, len)
}
Expand All @@ -458,6 +459,7 @@ library Arrays {
* WARNING: this does not clear elements if length is reduced, of initialize elements if length is increased.
*/
function unsafeSetLength(bytes32[] storage array, uint256 len) internal {
/// @solidity memory-safe-assembly
assembly {
sstore(array.slot, len)
}
Expand All @@ -469,6 +471,7 @@ library Arrays {
* WARNING: this does not clear elements if length is reduced, of initialize elements if length is increased.
*/
function unsafeSetLength(uint256[] storage array, uint256 len) internal {
/// @solidity memory-safe-assembly
assembly {
sstore(array.slot, len)
}
Expand Down
10 changes: 5 additions & 5 deletions contracts/utils/structs/CircularBuffer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import {Panic} from "../Panic.sol";
* Last N elements can be accessed using their index from the end.
*
* Complexity:
* - insertion (`push`): O(1)
* - lookup (`last`): O(1)
* - inclusion (`includes`): O(N) (worst case)
* - reset (`clear`): O(1)
* - insertion ({push}): O(1)
* - lookup ({last}): O(1)
* - inclusion ({includes}): O(N) (worst case)
* - reset ({clear}): O(1)
*
* * The struct is called `Bytes32CircularBuffer`. Other types can be cast to and from `bytes32`. This data structure
* can only be used in storage, and not in memory.
Expand Down Expand Up @@ -67,7 +67,7 @@ library CircularBuffer {
}

/**
* @dev Number of values currently in the buffer. This values is 0 for empty buffer, and cannot exceed the size of
* @dev Number of values currently in the buffer. This value is 0 for an empty buffer, and cannot exceed the size of
* the buffer.
*/
function count(Bytes32CircularBuffer storage self) internal view returns (uint256) {
Expand Down