Skip to content
Open
Changes from all commits
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
3 changes: 3 additions & 0 deletions src/include/zvec/ailego/container/heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ class Heap : public TBase {

//! Pop the front element
void pop(void) {
if (TBase::empty()) {
return;
}
Comment on lines +94 to +96
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Silent no-op changes documented API contract

The pre-existing test file (tests/ailego/container/heap_test.cc, line 234) explicitly documents the original design intent:

// heap.pop(); // disallowed

This indicates that pop() on an empty heap was intentionally a caller-side precondition, analogous to std::priority_queue::pop() (which is UB when empty). Changing the implementation to a silent no-op reverses that contract without updating the documentation comment, and it can silently mask logic bugs at call sites where the caller incorrectly tracks heap size.

If the intent is truly to make this safe to call unconditionally, the stale // disallowed comment in the test should be removed and a positive test for the empty-pop case should be added to heap_test.cc. As written, the PR description claims "comprehensive test cases" were added but no test file changes appear in the diff.

if (TBase::size() > 1) {
auto last = TBase::end() - 1;
this->replace_heap(TBase::begin(), last, std::move(*last));
Expand Down