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.
| Type | Intent | Optional | 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. |
| Type | Visibility | Attributes | Name | Initial | |||
|---|---|---|---|---|---|---|---|
| integer(kind=default_int), | private, | parameter | :: | DOUBLING_LIMIT | = | huge(0_default_int)/SOA_GROWTH_FACTOR |
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