soa_grow_capacity Function

public pure function soa_grow_capacity(current_capacity, required) result(new_capacity)

Capacity that covers required elements under the geometric policy.

Returns current_capacity unchanged when it is already enough, so capacity never shrinks here. Otherwise it starts from max(current_capacity, SOA_MIN_CAPACITY) and multiplies by SOA_GROWTH_FACTOR until it covers the request. Near the top of the integer range doubling would overflow, so the exact request is used instead; that is the only point where growth is not geometric.

Arguments

Type IntentOptional Attributes Name
integer(kind=default_int), intent(in) :: current_capacity

Capacity the container has now.

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

Number of elements that must fit.

Return Value integer(kind=default_int)


Called by

proc~~soa_grow_capacity~~CalledByGraph proc~soa_grow_capacity soa_grow_capacity proc~soa_plan_resize soa_plan_resize proc~soa_plan_resize->proc~soa_grow_capacity 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

Variables

Type Visibility Attributes Name Initial
integer(kind=default_int), private, parameter :: DOUBLING_LIMIT = huge(0_default_int)/SOA_GROWTH_FACTOR

Source Code

   pure function soa_grow_capacity(current_capacity, required) result(new_capacity)
      !! Capacity that covers `required` elements under the geometric policy.
      !!
      !! Returns `current_capacity` unchanged when it is already enough, so
      !! capacity never shrinks here. Otherwise it starts from
      !! `max(current_capacity, SOA_MIN_CAPACITY)` and multiplies by
      !! `SOA_GROWTH_FACTOR` until it covers the request. Near the top of the
      !! integer range doubling would overflow, so the exact request is used
      !! instead; that is the only point where growth is not geometric.
      integer(default_int), intent(in) :: current_capacity
         !! Capacity the container has now.
      integer(default_int), intent(in) :: required
         !! Number of elements that must fit.
      integer(default_int) :: new_capacity

      integer(default_int), parameter :: DOUBLING_LIMIT = huge(0_default_int)/SOA_GROWTH_FACTOR

      if (required <= current_capacity) then
         new_capacity = current_capacity
         return
      end if

      new_capacity = max(current_capacity, SOA_MIN_CAPACITY)
      do while (new_capacity < required)
         if (new_capacity > DOUBLING_LIMIT) then
            new_capacity = required
         else
            new_capacity = new_capacity*SOA_GROWTH_FACTOR
         end if
      end do
   end function soa_grow_capacity