vec_int64_append Subroutine

private pure subroutine vec_int64_append(self, values, err)

Append many elements, growing once rather than once per element.

Type Bound

vector_int64_t

Arguments

Type IntentOptional Attributes Name
class(vector_int64_t), intent(inout) :: self
integer(kind=int64), intent(in) :: values(:)
type(error_t), intent(inout), optional :: err

Calls

proc~~vec_int64_append~~CallsGraph proc~vec_int64_append vector_int64_t%vec_int64_append proc~error_raise error_raise proc~vec_int64_append->proc~error_raise proc~vec_int64_capacity vector_int64_t%vec_int64_capacity proc~vec_int64_append->proc~vec_int64_capacity proc~vec_int64_grow vec_int64_grow proc~vec_int64_append->proc~vec_int64_grow proc~error_set error_t%error_set proc~error_raise->proc~error_set proc~vec_int64_grow->proc~error_raise proc~vec_int64_grow->proc~vec_int64_capacity

Variables

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

Source Code

   pure subroutine vec_int64_append(self, values, err)
      !! Append many elements, growing once rather than once per element.
      class(vector_int64_t), intent(inout) :: self
      integer(int64), intent(in) :: values(:)
      type(error_t), intent(inout), optional :: err

      integer(default_int) :: n_new

      n_new = size(values, kind=default_int)
      if (n_new == 0) return

      ! Rearranged from `n_items + n_new > MAX` so that the sum is never
      ! formed; the subtraction cannot overflow because `n_items` is
      ! non-negative and PIC_VECTOR_MAX_CAPACITY is `huge`.
      if (n_new > PIC_VECTOR_MAX_CAPACITY - self%n_items) then
         call error_raise(err, ERROR_ALLOC, &
                          "vector_int64_t: append would exceed PIC_VECTOR_MAX_CAPACITY.")
         return
      end if

      call vec_int64_grow(self, self%n_items + n_new, err)
      if (self%n_items + n_new > vec_int64_capacity(self)) return

      self%items(self%n_items + 1:self%n_items + n_new) = values
      self%n_items = self%n_items + n_new
   end subroutine vec_int64_append