heap_init Subroutine

private subroutine heap_init(self, cap, max_heap)

Initialise the heap, discarding any previous contents.

cap pre-allocates storage for at least that many entries (default DEFAULT_CAPACITY); a non-positive cap allocates nothing yet. max_heap = .true. selects max-heap ordering, the default is a min-heap. Calling init on a heap that already holds entries resets it to empty but keeps any storage it had already acquired.

Type Bound

heap_t

Arguments

Type IntentOptional Attributes Name
class(heap_t), intent(inout) :: self
integer(kind=default_int), intent(in), optional :: cap
logical, intent(in), optional :: max_heap

Calls

proc~~heap_init~~CallsGraph proc~heap_init heap_t%heap_init proc~heap_reserve heap_t%heap_reserve proc~heap_init->proc~heap_reserve proc~grow_int32 grow_int32 proc~heap_reserve->proc~grow_int32 proc~grow_int64 grow_int64 proc~heap_reserve->proc~grow_int64 proc~heap_capacity heap_t%heap_capacity proc~heap_reserve->proc~heap_capacity

Called by

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

Variables

Type Visibility Attributes Name Initial
integer(kind=default_int), private :: wanted

Source Code

   subroutine heap_init(self, cap, max_heap)
      !! Initialise the heap, discarding any previous contents.
      !!
      !! `cap` pre-allocates storage for at least that many entries (default
      !! `DEFAULT_CAPACITY`); a non-positive `cap` allocates nothing yet.
      !! `max_heap = .true.` selects max-heap ordering, the default is a
      !! min-heap. Calling `init` on a heap that already holds entries resets
      !! it to empty but keeps any storage it had already acquired.
      class(heap_t), intent(inout) :: self
      integer(default_int), intent(in), optional :: cap
      logical, intent(in), optional :: max_heap

      integer(default_int) :: wanted

      self%n_entries = 0
      self%n_pushed = 0_int64
      self%max_heap = .false.
      if (present(max_heap)) self%max_heap = max_heap

      wanted = DEFAULT_CAPACITY
      if (present(cap)) wanted = cap

      call self%reserve(wanted)
   end subroutine heap_init