소스 검색

Correctly handle extracting the last element of a heap

Ian Goldberg 1 년 전
부모
커밋
4e5e850268
1개의 변경된 파일6개의 추가작업 그리고 0개의 파일을 삭제
  1. 6 0
      heap.cpp

+ 6 - 0
heap.cpp

@@ -664,6 +664,12 @@ RegAS MinHeap::extract_min(MPCTIO &tio, yield_t & yield, int is_optimized) {
     v.ashare = 0x7fffffffffffff * !tio.player();
     HeapArray[num_items] = v;
     num_items--;
+
+    // If this was the last item, just return it
+    if (num_items == 0) {
+        return minval;
+    }
+
     auto outroot = restore_heap_property_at_explicit_index(tio, yield);
     RegXS smaller = outroot.first;