vector_dp_t Derived Type

type, public :: vector_dp_t

Growable array of real(dp).


Components

Type Visibility Attributes Name Initial
real(kind=dp), private, allocatable :: items(:)

Backing storage. Only items(1:n_items) is meaningful; the rest is spare capacity whose contents are unspecified.

integer(kind=default_int), private :: n_items = 0

Number of live elements. Always 0 <= n_items <= capacity().


Type-Bound Procedures

procedure, public :: append => vec_dp_append

  • private pure subroutine vec_dp_append(self, values, err)

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

    Arguments

    Type IntentOptional Attributes Name
    class(vector_dp_t), intent(inout) :: self
    real(kind=dp), intent(in) :: values(:)
    type(error_t), intent(inout), optional :: err

procedure, public :: as_array => vec_dp_as_array

  • private pure function vec_dp_as_array(self) result(copy)

    A copy holding exactly size() elements.

    Arguments

    Type IntentOptional Attributes Name
    class(vector_dp_t), intent(in) :: self

    Return Value real(kind=dp), allocatable, (:)

procedure, public :: at => vec_dp_at

  • private pure subroutine vec_dp_at(self, index, value, err)

    Read element index, 1-based. ERROR_BOUNDS when out of range.

    Arguments

    Type IntentOptional Attributes Name
    class(vector_dp_t), intent(in) :: self
    integer(kind=default_int), intent(in) :: index
    real(kind=dp), intent(out) :: value
    type(error_t), intent(inout), optional :: err

procedure, public :: capacity => vec_dp_capacity

  • private pure function vec_dp_capacity(self) result(n)

    Elements that fit before the next reallocation.

    Arguments

    Type IntentOptional Attributes Name
    class(vector_dp_t), intent(in) :: self

    Return Value integer(kind=default_int)

procedure, public :: clear => vec_dp_clear

  • private pure subroutine vec_dp_clear(self)

    Drop every element but keep the allocated storage, so a vector reused across iterations of an outer loop stops reallocating.

    Arguments

    Type IntentOptional Attributes Name
    class(vector_dp_t), intent(inout) :: self

procedure, public :: destroy => vec_dp_destroy

  • private pure subroutine vec_dp_destroy(self)

    Release all storage and reset to the empty state.

    Arguments

    Type IntentOptional Attributes Name
    class(vector_dp_t), intent(inout) :: self

procedure, public :: get_unchecked => vec_dp_get_unchecked

  • private pure function vec_dp_get_unchecked(self, index) result(value)

    Element index with no bounds check, for hot loops that have already established the range. Reading outside 1:size() is undefined.

    Arguments

    Type IntentOptional Attributes Name
    class(vector_dp_t), intent(in) :: self
    integer(kind=default_int), intent(in) :: index

    Return Value real(kind=dp)

procedure, public :: is_empty => vec_dp_is_empty

  • private pure function vec_dp_is_empty(self) result(flag)

    .true. when there are no live elements.

    Arguments

    Type IntentOptional Attributes Name
    class(vector_dp_t), intent(in) :: self

    Return Value logical

procedure, public :: pop_back => vec_dp_pop_back

  • private pure subroutine vec_dp_pop_back(self, value, err)

    Remove and return the last element. ERROR_BOUNDS when empty, in which case the vector is unchanged.

    Arguments

    Type IntentOptional Attributes Name
    class(vector_dp_t), intent(inout) :: self
    real(kind=dp), intent(out) :: value
    type(error_t), intent(inout), optional :: err

procedure, public :: push_back => vec_dp_push_back

  • private pure subroutine vec_dp_push_back(self, value, err)

    Append one element. ERROR_ALLOC if storage cannot be grown, in which case the vector is unchanged.

    Arguments

    Type IntentOptional Attributes Name
    class(vector_dp_t), intent(inout) :: self
    real(kind=dp), intent(in) :: value
    type(error_t), intent(inout), optional :: err

procedure, public :: reserve => vec_dp_reserve

  • private pure subroutine vec_dp_reserve(self, n, err)

    Make room for at least n elements. size() is unchanged.

    Arguments

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

procedure, public :: resize => vec_dp_resize

  • private pure subroutine vec_dp_resize(self, n, fill, err)

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

    Arguments

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

procedure, public :: set => vec_dp_set

  • private pure subroutine vec_dp_set(self, index, value, err)

    Overwrite element index, 1-based. ERROR_BOUNDS when out of range; this never extends the vector, use push_back or resize for that.

    Arguments

    Type IntentOptional Attributes Name
    class(vector_dp_t), intent(inout) :: self
    integer(kind=default_int), intent(in) :: index
    real(kind=dp), intent(in) :: value
    type(error_t), intent(inout), optional :: err

procedure, public :: shrink_to_fit => vec_dp_shrink_to_fit

  • private pure subroutine vec_dp_shrink_to_fit(self, err)

    Release capacity beyond size().

    Arguments

    Type IntentOptional Attributes Name
    class(vector_dp_t), intent(inout) :: self
    type(error_t), intent(inout), optional :: err

procedure, public :: size => vec_dp_size

  • private pure function vec_dp_size(self) result(n)

    Number of live elements.

    Arguments

    Type IntentOptional Attributes Name
    class(vector_dp_t), intent(in) :: self

    Return Value integer(kind=default_int)

procedure, public :: take => vec_dp_take

  • private pure subroutine vec_dp_take(self, array, err)

    Hand the storage over to array, exactly sized, without copying the elements. The vector is left empty and without storage.

    Read more…

    Arguments

    Type IntentOptional Attributes Name
    class(vector_dp_t), intent(inout) :: self
    real(kind=dp), intent(out), allocatable :: array(:)
    type(error_t), intent(inout), optional :: err

Source Code

   type :: vector_dp_t
      !! Growable array of real(dp).
      integer(default_int), private :: n_items = 0
         !! Number of live elements. Always `0 <= n_items <= capacity()`.
      real(dp), allocatable, private :: items(:)
         !! Backing storage. Only `items(1:n_items)` is meaningful; the rest is
         !! spare capacity whose contents are unspecified.
   contains
      procedure :: push_back => vec_dp_push_back
      procedure :: append => vec_dp_append
      procedure :: pop_back => vec_dp_pop_back
      procedure :: at => vec_dp_at
      procedure :: set => vec_dp_set
      procedure :: get_unchecked => vec_dp_get_unchecked
      procedure :: size => vec_dp_size
      procedure :: capacity => vec_dp_capacity
      procedure :: is_empty => vec_dp_is_empty
      procedure :: reserve => vec_dp_reserve
      procedure :: resize => vec_dp_resize
      procedure :: clear => vec_dp_clear
      procedure :: shrink_to_fit => vec_dp_shrink_to_fit
      procedure :: as_array => vec_dp_as_array
      procedure :: take => vec_dp_take
      procedure :: destroy => vec_dp_destroy
   end type vector_dp_t