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 | Intent | Optional | 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, |
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