soa_plan_resize Subroutine

public subroutine soa_plan_resize(extent, new_size, new_capacity, keep, err)

Work out what a resize to new_size elements has to do.

Computes the capacity every field array must end up with and how many leading elements carry over. Does not touch extent: the caller updates it once every field has actually been resized, so a failed resize leaves the container consistent with its fields.

Arguments

Type IntentOptional Attributes Name
type(soa_extent_t), intent(in) :: extent

Current size and capacity of the container.

integer(kind=default_int), intent(in) :: new_size

Requested number of live elements.

integer(kind=default_int), intent(out) :: new_capacity

Capacity the field arrays must have afterwards.

integer(kind=default_int), intent(out) :: keep

Number of leading elements whose values must survive.

type(error_t), intent(inout) :: err

Error state, ERROR_VALIDATION when new_size is negative.


Calls

proc~~soa_plan_resize~~CallsGraph proc~soa_plan_resize soa_plan_resize interface~to_char to_char proc~soa_plan_resize->interface~to_char proc~error_set error_t%error_set proc~soa_plan_resize->proc~error_set proc~soa_grow_capacity soa_grow_capacity proc~soa_plan_resize->proc~soa_grow_capacity proc~to_char_char to_char_char interface~to_char->proc~to_char_char proc~to_char_dp to_char_dp interface~to_char->proc~to_char_dp proc~to_char_int32 to_char_int32 interface~to_char->proc~to_char_int32 proc~to_char_int64 to_char_int64 interface~to_char->proc~to_char_int64 proc~to_char_logical to_char_logical interface~to_char->proc~to_char_logical proc~to_char_matrix_dp to_char_matrix_dp interface~to_char->proc~to_char_matrix_dp proc~to_char_matrix_int32 to_char_matrix_int32 interface~to_char->proc~to_char_matrix_int32 proc~to_char_matrix_int64 to_char_matrix_int64 interface~to_char->proc~to_char_matrix_int64 proc~to_char_matrix_sp to_char_matrix_sp interface~to_char->proc~to_char_matrix_sp proc~to_char_sp to_char_sp interface~to_char->proc~to_char_sp proc~to_char_vector_dp to_char_vector_dp interface~to_char->proc~to_char_vector_dp proc~to_char_vector_int32 to_char_vector_int32 interface~to_char->proc~to_char_vector_int32 proc~to_char_vector_int64 to_char_vector_int64 interface~to_char->proc~to_char_vector_int64 proc~to_char_vector_sp to_char_vector_sp interface~to_char->proc~to_char_vector_sp

Called by

proc~~soa_plan_resize~~CalledByGraph proc~soa_plan_resize soa_plan_resize proc~particle_soa_resize particle_soa_t%particle_soa_resize proc~particle_soa_resize->proc~soa_plan_resize proc~particle_soa_allocate particle_soa_t%particle_soa_allocate proc~particle_soa_allocate->proc~particle_soa_resize

Source Code

   subroutine soa_plan_resize(extent, new_size, new_capacity, keep, err)
      !! Work out what a resize to `new_size` elements has to do.
      !!
      !! Computes the capacity every field array must end up with and how many
      !! leading elements carry over. Does not touch `extent`: the caller
      !! updates it once every field has actually been resized, so a failed
      !! resize leaves the container consistent with its fields.
      type(soa_extent_t), intent(in) :: extent
         !! Current size and capacity of the container.
      integer(default_int), intent(in) :: new_size
         !! Requested number of live elements.
      integer(default_int), intent(out) :: new_capacity
         !! Capacity the field arrays must have afterwards.
      integer(default_int), intent(out) :: keep
         !! Number of leading elements whose values must survive.
      type(error_t), intent(inout) :: err
         !! Error state, `ERROR_VALIDATION` when `new_size` is negative.

      new_capacity = extent%capacity
      keep = 0

      if (new_size < 0) then
         call err%set(ERROR_VALIDATION, "soa: requested size "//to_char(int(new_size, int64))// &
                      " is negative")
         return
      end if

      keep = min(extent%used, new_size)
      if (new_size > extent%capacity) then
         new_capacity = soa_grow_capacity(extent%capacity, new_size)
      end if
   end subroutine soa_plan_resize