vec_int32_resize Subroutine

private pure subroutine vec_int32_resize(self, n, fill, err)

Set the length to n, padding with fill when growing and dropping elements from the end when shrinking.

Type Bound

vector_int32_t

Arguments

Type IntentOptional Attributes Name
class(vector_int32_t), intent(inout) :: self
integer(kind=default_int), intent(in) :: n
integer(kind=int32), intent(in) :: fill
type(error_t), intent(inout), optional :: err

Calls

proc~~vec_int32_resize~~CallsGraph proc~vec_int32_resize vector_int32_t%vec_int32_resize proc~error_raise error_raise proc~vec_int32_resize->proc~error_raise proc~vec_int32_capacity vector_int32_t%vec_int32_capacity proc~vec_int32_resize->proc~vec_int32_capacity proc~vec_int32_grow vec_int32_grow proc~vec_int32_resize->proc~vec_int32_grow proc~error_set error_t%error_set proc~error_raise->proc~error_set proc~vec_int32_grow->proc~error_raise proc~vec_int32_grow->proc~vec_int32_capacity

Variables

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

Source Code

   pure subroutine vec_int32_resize(self, n, fill, err)
      !! Set the length to `n`, padding with `fill` when growing and dropping
      !! elements from the end when shrinking.
      class(vector_int32_t), intent(inout) :: self
      integer(default_int), intent(in) :: n
      integer(int32), intent(in) :: fill
      type(error_t), intent(inout), optional :: err

      integer(default_int) :: i

      if (n < 0) then
         call error_raise(err, ERROR_VALIDATION, "vector_int32_t: resize() to a negative length.")
         return
      end if

      if (n <= self%n_items) then
         self%n_items = n
         return
      end if

      call vec_int32_grow(self, n, err)
      if (n > vec_int32_capacity(self)) return

      do i = self%n_items + 1, n
         self%items(i) = fill
      end do
      self%n_items = n
   end subroutine vec_int32_resize