Skip to content

Commit 2f1386c

Browse files
authored
docs(Heap): clarify priority via comparator and default min-heap behavior (#6068)
1 parent a60b367 commit 2f1386c

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

contracts/utils/structs/Heap.sol

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ import {StorageSlot} from "../StorageSlot.sol";
1717
* index i is the child of the node at index (i-1)/2 and the parent of nodes at index 2*i+1 and 2*i+2. Each node
1818
* stores an element of the heap.
1919
*
20-
* The structure is ordered so that each node is bigger than its parent. An immediate consequence is that the
21-
* highest priority value is the one at the root. This value can be looked up in constant time (O(1)) at
22-
* `heap.tree[0]`
20+
* The structure is ordered so that, per the comparator, each node has lower priority than its parent; as a
21+
* consequence, the highest-priority value is at the root. This value can be looked up in constant time (O(1)) at
22+
* `heap.tree[0]`. By default, the comparator is `Comparators.lt`, which treats smaller values as higher priority
23+
* (min-heap). Using `Comparators.gt` yields a max-heap.
2324
*
2425
* The structure is designed to perform the following operations with the corresponding complexities:
2526
*

0 commit comments

Comments
 (0)