[Heap] Follow the spelling of stdlib’s min/max; add note explaining expectations

The existing expressions had the same effect, but they used different operators (`<=` instead of `<` and `>` instead of `>=`). The distinction is usually irrelevant, but there is no reason not to just follow what the stdlib is doing exactly.
This commit is contained in:
Karoy Lorentey committed 2025-05-15 17:30:25 -07:00
1 parent 5edd1be23c
commit d93a6ab8a1
1 file changed
+7 -2
+7 -2
View File
@@ -81,12 +81,17 @@ extension Heap._UnsafeHandle {
@inlinable @inline(__always)
internal func minValue(_ a: _HeapNode, _ b: _HeapNode) -> _HeapNode {
self[a] <= self[b] ? a : b
// The expression used here matches the implementation of the
// standard `Swift.min(_:_:)` function. This attempts to
// preserve any pre-existing order in case `T` has identity.
// `(min(x, y), max(x, y))` should return `(x, y)` in case `x == y`.
self[b] < self[a] ? b : a
}
@inlinable @inline(__always)
internal func maxValue(_ a: _HeapNode, _ b: _HeapNode) -> _HeapNode {
self[a] > self[b] ? a : b
// In case `a` and `b` match, we need to pick `b`. See `minValue(_:_:)`.
self[b] >= self[a] ? b : a
}
}