Remove and return the root entry (minimum, or maximum for a max-heap).
Popping an empty heap is an error, not a crash: key and payload
are set to zero and err reports ERROR_VALIDATION. err is
optional; when it is absent an empty pop simply yields zeros.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| class(heap_t), | intent(inout) | :: | self | |||
| integer(kind=int64), | intent(out) | :: | key | |||
| integer(kind=int32), | intent(out) | :: | payload | |||
| type(error_t), | intent(out), | optional | :: | err |
subroutine heap_pop(self, key, payload, err) !! Remove and return the root entry (minimum, or maximum for a max-heap). !! !! Popping an empty heap is an error, not a crash: `key` and `payload` !! are set to zero and `err` reports `ERROR_VALIDATION`. `err` is !! optional; when it is absent an empty pop simply yields zeros. class(heap_t), intent(inout) :: self integer(int64), intent(out) :: key integer(int32), intent(out) :: payload type(error_t), intent(out), optional :: err if (.not. root_entry(self, key, payload, err)) return self%keys(1) = self%keys(self%n_entries) self%payloads(1) = self%payloads(self%n_entries) self%insertion(1) = self%insertion(self%n_entries) self%n_entries = self%n_entries - 1 if (self%n_entries > 1) call sift_down(self, 1_default_int) end subroutine heap_pop