Skip to content

Commit 659f306

Browse files
authored
Fix typo in Heap.sol documentation (#5121)
1 parent 231fae3 commit 659f306

File tree

2 files changed

+32
-32
lines changed

2 files changed

+32
-32
lines changed

contracts/utils/structs/Heap.sol

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@ import {Panic} from "../Panic.sol";
2626
* ```
2727
*
2828
* The structure is ordered so that each node is bigger than its parent. An immediate consequence is that the
29-
* highest priority value is the one at the root. This value can be lookup up in constant time (O(1)) at
29+
* highest priority value is the one at the root. This value can be looked up in constant time (O(1)) at
3030
* `heap.data[heap.data[0].index].value`
3131
*
3232
* The structure is designed to perform the following operations with the corresponding complexities:
3333
*
34-
* * peek (get the highest priority in set): O(1)
35-
* * insert (insert a value in the set): 0(log(n))
36-
* * pop (remove the highest priority value in set): O(log(n))
37-
* * replace (replace the highest priority value in set with a new value): O(log(n))
38-
* * length (get the number of elements in the set): O(1)
39-
* * clear (remove all elements in the set): O(1)
34+
* * peek (get the highest priority value): O(1)
35+
* * insert (insert a value): O(log(n))
36+
* * pop (remove the highest priority value): O(log(n))
37+
* * replace (replace the highest priority value with a new value): O(log(n))
38+
* * length (get the number of elements): O(1)
39+
* * clear (remove all elements): O(1)
4040
*/
4141
library Heap {
4242
using Math for *;
@@ -45,7 +45,7 @@ library Heap {
4545
/**
4646
* @dev Binary heap that support values of type uint256.
4747
*
48-
* Each element of that structures uses 2 storage slots.
48+
* Each element of that structure uses 2 storage slots.
4949
*/
5050
struct Uint256Heap {
5151
Uint256HeapNode[] data;
@@ -101,9 +101,9 @@ library Heap {
101101
Uint256HeapNode storage lastNode = _unsafeNodeAccess(self, last);
102102
uint256 rootDataValue = rootData.value;
103103

104-
// if root is not the last element of the data array (that will get pop-ed), reorder the data array.
104+
// if root is not the last element of the data array (that will get popped), reorder the data array.
105105
if (rootIdx != last) {
106-
// get details about the value stored in the last element of the array (that will get pop-ed)
106+
// get details about the value stored in the last element of the array (that will get popped)
107107
uint64 lastDataIdx = lastNode.lookup;
108108
uint256 lastDataValue = lastNode.value;
109109
// copy these values to the location of the root (that is safe, and that we no longer use)
@@ -253,7 +253,7 @@ library Heap {
253253
uint256 right = 2 * pos + 2; // this could overflow uint64
254254

255255
if (right < size) {
256-
// the check guarantees that `left` and `right` are both valid uint32
256+
// the check guarantees that `left` and `right` are both valid uint64
257257
uint64 lIndex = uint64(left);
258258
uint64 rIndex = uint64(right);
259259
uint256 lValue = _unsafeNodeAccess(self, _unsafeNodeAccess(self, lIndex).index).value;
@@ -264,7 +264,7 @@ library Heap {
264264
_siftDown(self, size, index, value, comp);
265265
}
266266
} else if (left < size) {
267-
// the check guarantees that `left` is a valid uint32
267+
// the check guarantees that `left` is a valid uint64
268268
uint64 lIndex = uint64(left);
269269
uint256 lValue = _unsafeNodeAccess(self, _unsafeNodeAccess(self, lIndex).index).value;
270270
if (comp(lValue, value)) {
@@ -279,7 +279,7 @@ library Heap {
279279
* comparator, and moving toward the root of the underlying tree.
280280
*
281281
* NOTE: This is a private function that is called in a trusted context with already cached parameters. `value`
282-
* could be extracted from `self` and `pos`, but that would require redundant storage read. This parameters is not
282+
* could be extracted from `self` and `pos`, but that would require redundant storage read. These parameters are not
283283
* verified. It is the caller role to make sure the parameters are correct.
284284
*/
285285
function _siftUp(
@@ -312,7 +312,7 @@ library Heap {
312312
/**
313313
* @dev Binary heap that support values of type uint208.
314314
*
315-
* Each element of that structures uses 1 storage slots.
315+
* Each element of that structure uses 1 storage slots.
316316
*/
317317
struct Uint208Heap {
318318
Uint208HeapNode[] data;
@@ -368,9 +368,9 @@ library Heap {
368368
Uint208HeapNode storage lastNode = _unsafeNodeAccess(self, last);
369369
uint208 rootDataValue = rootData.value;
370370

371-
// if root is not the last element of the data array (that will get pop-ed), reorder the data array.
371+
// if root is not the last element of the data array (that will get popped), reorder the data array.
372372
if (rootIdx != last) {
373-
// get details about the value stored in the last element of the array (that will get pop-ed)
373+
// get details about the value stored in the last element of the array (that will get popped)
374374
uint24 lastDataIdx = lastNode.lookup;
375375
uint208 lastDataValue = lastNode.value;
376376
// copy these values to the location of the root (that is safe, and that we no longer use)
@@ -520,7 +520,7 @@ library Heap {
520520
uint256 right = 2 * pos + 2; // this could overflow uint24
521521

522522
if (right < size) {
523-
// the check guarantees that `left` and `right` are both valid uint32
523+
// the check guarantees that `left` and `right` are both valid uint24
524524
uint24 lIndex = uint24(left);
525525
uint24 rIndex = uint24(right);
526526
uint208 lValue = _unsafeNodeAccess(self, _unsafeNodeAccess(self, lIndex).index).value;
@@ -531,7 +531,7 @@ library Heap {
531531
_siftDown(self, size, index, value, comp);
532532
}
533533
} else if (left < size) {
534-
// the check guarantees that `left` is a valid uint32
534+
// the check guarantees that `left` is a valid uint24
535535
uint24 lIndex = uint24(left);
536536
uint208 lValue = _unsafeNodeAccess(self, _unsafeNodeAccess(self, lIndex).index).value;
537537
if (comp(lValue, value)) {
@@ -546,7 +546,7 @@ library Heap {
546546
* comparator, and moving toward the root of the underlying tree.
547547
*
548548
* NOTE: This is a private function that is called in a trusted context with already cached parameters. `value`
549-
* could be extracted from `self` and `pos`, but that would require redundant storage read. This parameters is not
549+
* could be extracted from `self` and `pos`, but that would require redundant storage read. These parameters are not
550550
* verified. It is the caller role to make sure the parameters are correct.
551551
*/
552552
function _siftUp(

scripts/generate/templates/Heap.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,25 @@ import {Panic} from "../Panic.sol";
2929
* \`\`\`
3030
*
3131
* The structure is ordered so that each node is bigger than its parent. An immediate consequence is that the
32-
* highest priority value is the one at the root. This value can be lookup up in constant time (O(1)) at
32+
* highest priority value is the one at the root. This value can be looked up in constant time (O(1)) at
3333
* \`heap.data[heap.data[0].index].value\`
3434
*
3535
* The structure is designed to perform the following operations with the corresponding complexities:
3636
*
37-
* * peek (get the highest priority in set): O(1)
38-
* * insert (insert a value in the set): 0(log(n))
39-
* * pop (remove the highest priority value in set): O(log(n))
40-
* * replace (replace the highest priority value in set with a new value): O(log(n))
41-
* * length (get the number of elements in the set): O(1)
42-
* * clear (remove all elements in the set): O(1)
37+
* * peek (get the highest priority value): O(1)
38+
* * insert (insert a value): O(log(n))
39+
* * pop (remove the highest priority value): O(log(n))
40+
* * replace (replace the highest priority value with a new value): O(log(n))
41+
* * length (get the number of elements): O(1)
42+
* * clear (remove all elements): O(1)
4343
*/
4444
`;
4545

4646
const generate = ({ struct, node, valueType, indexType, blockSize }) => `\
4747
/**
4848
* @dev Binary heap that support values of type ${valueType}.
4949
*
50-
* Each element of that structures uses ${blockSize} storage slots.
50+
* Each element of that structure uses ${blockSize} storage slots.
5151
*/
5252
struct ${struct} {
5353
${node}[] data;
@@ -103,9 +103,9 @@ function pop(
103103
${node} storage lastNode = _unsafeNodeAccess(self, last);
104104
${valueType} rootDataValue = rootData.value;
105105
106-
// if root is not the last element of the data array (that will get pop-ed), reorder the data array.
106+
// if root is not the last element of the data array (that will get popped), reorder the data array.
107107
if (rootIdx != last) {
108-
// get details about the value stored in the last element of the array (that will get pop-ed)
108+
// get details about the value stored in the last element of the array (that will get popped)
109109
${indexType} lastDataIdx = lastNode.lookup;
110110
${valueType} lastDataValue = lastNode.value;
111111
// copy these values to the location of the root (that is safe, and that we no longer use)
@@ -255,7 +255,7 @@ function _siftDown(
255255
uint256 right = 2 * pos + 2; // this could overflow ${indexType}
256256
257257
if (right < size) {
258-
// the check guarantees that \`left\` and \`right\` are both valid uint32
258+
// the check guarantees that \`left\` and \`right\` are both valid ${indexType}
259259
${indexType} lIndex = ${indexType}(left);
260260
${indexType} rIndex = ${indexType}(right);
261261
${valueType} lValue = _unsafeNodeAccess(self, _unsafeNodeAccess(self, lIndex).index).value;
@@ -266,7 +266,7 @@ function _siftDown(
266266
_siftDown(self, size, index, value, comp);
267267
}
268268
} else if (left < size) {
269-
// the check guarantees that \`left\` is a valid uint32
269+
// the check guarantees that \`left\` is a valid ${indexType}
270270
${indexType} lIndex = ${indexType}(left);
271271
${valueType} lValue = _unsafeNodeAccess(self, _unsafeNodeAccess(self, lIndex).index).value;
272272
if (comp(lValue, value)) {
@@ -281,7 +281,7 @@ function _siftDown(
281281
* comparator, and moving toward the root of the underlying tree.
282282
*
283283
* NOTE: This is a private function that is called in a trusted context with already cached parameters. \`value\`
284-
* could be extracted from \`self\` and \`pos\`, but that would require redundant storage read. This parameters is not
284+
* could be extracted from \`self\` and \`pos\`, but that would require redundant storage read. These parameters are not
285285
* verified. It is the caller role to make sure the parameters are correct.
286286
*/
287287
function _siftUp(

0 commit comments

Comments
 (0)