Explorar el Código

Correctly handle extracting the last element of a heap

Ian Goldberg hace 6 meses
padre
commit
4e5e850268
Se han modificado 1 ficheros con 6 adiciones y 0 borrados
  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;