@@ -26,17 +26,17 @@ import {Panic} from "../Panic.sol";
26
26
* ```
27
27
*
28
28
* 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
30
30
* `heap.data[heap.data[0].index].value`
31
31
*
32
32
* The structure is designed to perform the following operations with the corresponding complexities:
33
33
*
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)
40
40
*/
41
41
library Heap {
42
42
using Math for * ;
@@ -45,7 +45,7 @@ library Heap {
45
45
/**
46
46
* @dev Binary heap that support values of type uint256.
47
47
*
48
- * Each element of that structures uses 2 storage slots.
48
+ * Each element of that structure uses 2 storage slots.
49
49
*/
50
50
struct Uint256Heap {
51
51
Uint256HeapNode[] data;
@@ -101,9 +101,9 @@ library Heap {
101
101
Uint256HeapNode storage lastNode = _unsafeNodeAccess (self, last);
102
102
uint256 rootDataValue = rootData.value;
103
103
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.
105
105
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 )
107
107
uint64 lastDataIdx = lastNode.lookup;
108
108
uint256 lastDataValue = lastNode.value;
109
109
// copy these values to the location of the root (that is safe, and that we no longer use)
@@ -253,7 +253,7 @@ library Heap {
253
253
uint256 right = 2 * pos + 2 ; // this could overflow uint64
254
254
255
255
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
257
257
uint64 lIndex = uint64 (left);
258
258
uint64 rIndex = uint64 (right);
259
259
uint256 lValue = _unsafeNodeAccess (self, _unsafeNodeAccess (self, lIndex).index).value;
@@ -264,7 +264,7 @@ library Heap {
264
264
_siftDown (self, size, index, value, comp);
265
265
}
266
266
} else if (left < size) {
267
- // the check guarantees that `left` is a valid uint32
267
+ // the check guarantees that `left` is a valid uint64
268
268
uint64 lIndex = uint64 (left);
269
269
uint256 lValue = _unsafeNodeAccess (self, _unsafeNodeAccess (self, lIndex).index).value;
270
270
if (comp (lValue, value)) {
@@ -279,7 +279,7 @@ library Heap {
279
279
* comparator, and moving toward the root of the underlying tree.
280
280
*
281
281
* 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
283
283
* verified. It is the caller role to make sure the parameters are correct.
284
284
*/
285
285
function _siftUp (
@@ -312,7 +312,7 @@ library Heap {
312
312
/**
313
313
* @dev Binary heap that support values of type uint208.
314
314
*
315
- * Each element of that structures uses 1 storage slots.
315
+ * Each element of that structure uses 1 storage slots.
316
316
*/
317
317
struct Uint208Heap {
318
318
Uint208HeapNode[] data;
@@ -368,9 +368,9 @@ library Heap {
368
368
Uint208HeapNode storage lastNode = _unsafeNodeAccess (self, last);
369
369
uint208 rootDataValue = rootData.value;
370
370
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.
372
372
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 )
374
374
uint24 lastDataIdx = lastNode.lookup;
375
375
uint208 lastDataValue = lastNode.value;
376
376
// copy these values to the location of the root (that is safe, and that we no longer use)
@@ -520,7 +520,7 @@ library Heap {
520
520
uint256 right = 2 * pos + 2 ; // this could overflow uint24
521
521
522
522
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
524
524
uint24 lIndex = uint24 (left);
525
525
uint24 rIndex = uint24 (right);
526
526
uint208 lValue = _unsafeNodeAccess (self, _unsafeNodeAccess (self, lIndex).index).value;
@@ -531,7 +531,7 @@ library Heap {
531
531
_siftDown (self, size, index, value, comp);
532
532
}
533
533
} else if (left < size) {
534
- // the check guarantees that `left` is a valid uint32
534
+ // the check guarantees that `left` is a valid uint24
535
535
uint24 lIndex = uint24 (left);
536
536
uint208 lValue = _unsafeNodeAccess (self, _unsafeNodeAccess (self, lIndex).index).value;
537
537
if (comp (lValue, value)) {
@@ -546,7 +546,7 @@ library Heap {
546
546
* comparator, and moving toward the root of the underlying tree.
547
547
*
548
548
* 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
550
550
* verified. It is the caller role to make sure the parameters are correct.
551
551
*/
552
552
function _siftUp (
0 commit comments