grow_int64 Subroutine

private subroutine grow_int64(arr, n_keep, new_cap)

Reallocate arr to new_cap slots, keeping its first n_keep values.

Deliberately written as explicit allocate/copy/deallocate rather than move_alloc or reallocation-on-assignment: both have historically been unreliable on nvfortran and LFortran, and this path runs only O(log n) times over the life of a heap.

Arguments

Type IntentOptional Attributes Name
integer(kind=int64), intent(inout), allocatable :: arr(:)
integer(kind=default_int), intent(in) :: n_keep
integer(kind=default_int), intent(in) :: new_cap

Called by

proc~~grow_int64~~CalledByGraph proc~grow_int64 grow_int64 proc~heap_reserve heap_t%heap_reserve proc~heap_reserve->proc~grow_int64 proc~heap_build_from heap_t%heap_build_from proc~heap_build_from->proc~heap_reserve proc~heap_init heap_t%heap_init proc~heap_init->proc~heap_reserve proc~heap_push heap_t%heap_push proc~heap_push->proc~heap_reserve proc~a_star a_star proc~a_star->proc~heap_init proc~a_star->proc~heap_push proc~dijkstra dijkstra proc~dijkstra->proc~heap_init proc~dijkstra->proc~heap_push

Variables

Type Visibility Attributes Name Initial
integer(kind=default_int), private :: i
integer(kind=int64), private, allocatable :: tmp(:)

Source Code

   subroutine grow_int64(arr, n_keep, new_cap)
      !! Reallocate `arr` to `new_cap` slots, keeping its first `n_keep` values.
      !!
      !! Deliberately written as explicit allocate/copy/deallocate rather than
      !! `move_alloc` or reallocation-on-assignment: both have historically
      !! been unreliable on nvfortran and LFortran, and this path runs only
      !! O(log n) times over the life of a heap.
      integer(int64), allocatable, intent(inout) :: arr(:)
      integer(default_int), intent(in) :: n_keep
      integer(default_int), intent(in) :: new_cap

      integer(int64), allocatable :: tmp(:)
      integer(default_int) :: i

      if (.not. allocated(arr)) then
         allocate (arr(new_cap))
         return
      end if

      allocate (tmp(n_keep))
      do i = 1, n_keep
         tmp(i) = arr(i)
      end do

      deallocate (arr)
      allocate (arr(new_cap))
      do i = 1, n_keep
         arr(i) = tmp(i)
      end do

      deallocate (tmp)
   end subroutine grow_int64