heap_push Subroutine

private subroutine heap_push(self, key, payload)

Insert one (key, payload) entry in O(log n).

Entries pushed earlier pop before equal-key entries pushed later.

Type Bound

heap_t

Arguments

Type IntentOptional Attributes Name
class(heap_t), intent(inout) :: self
integer(kind=int64), intent(in) :: key
integer(kind=int32), intent(in) :: payload

Calls

proc~~heap_push~~CallsGraph proc~heap_push heap_t%heap_push proc~heap_capacity heap_t%heap_capacity proc~heap_push->proc~heap_capacity proc~heap_reserve heap_t%heap_reserve proc~heap_push->proc~heap_reserve proc~sift_up sift_up proc~heap_push->proc~sift_up proc~heap_reserve->proc~heap_capacity proc~grow_int32 grow_int32 proc~heap_reserve->proc~grow_int32 proc~grow_int64 grow_int64 proc~heap_reserve->proc~grow_int64 proc~precedes precedes proc~sift_up->proc~precedes proc~swap_entries swap_entries proc~sift_up->proc~swap_entries

Called by

proc~~heap_push~~CalledByGraph proc~heap_push heap_t%heap_push proc~a_star a_star proc~a_star->proc~heap_push proc~dijkstra dijkstra proc~dijkstra->proc~heap_push

Source Code

   subroutine heap_push(self, key, payload)
      !! Insert one (key, payload) entry in O(log n).
      !!
      !! Entries pushed earlier pop before equal-key entries pushed later.
      class(heap_t), intent(inout) :: self
      integer(int64), intent(in) :: key
      integer(int32), intent(in) :: payload

      if (self%n_entries >= self%capacity()) then
         call self%reserve(max(DEFAULT_CAPACITY, GROWTH_FACTOR*self%capacity()))
      end if

      self%n_entries = self%n_entries + 1
      self%n_pushed = self%n_pushed + 1_int64
      self%keys(self%n_entries) = key
      self%payloads(self%n_entries) = payload
      self%insertion(self%n_entries) = self%n_pushed

      call sift_up(self, self%n_entries)
   end subroutine heap_push