def sort_heap_updates(heap_updates, num_heap_updates):
    """Take an array of unsorted heap updates and sort by row number."""
    row_numbers = heap_updates[:num_heap_updates, 0]
    # use mergesort since it is stable (and supported by numba)
    heap_updates[:num_heap_updates] = heap_updates[:num_heap_updates][
        row_numbers.argsort(kind="mergesort")
    ]
    return heap_updates