fixed_array_dp_t Derived Type

type, public :: fixed_array_dp_t

Bounded array of real(dp) with fixed inline storage.


Components

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

Inline storage. Deliberately not allocatable: no heap, ever. Elements above n_items are undefined and must not be read.

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

Number of live elements, always in 0:PIC_FIXED_ARRAY_CAPACITY


Type-Bound Procedures

procedure, public :: as_array => fixed_array_dp_as_array

  • private pure function fixed_array_dp_as_array(self) result(arr)

    Copy of the live elements as a plain array of extent size(), not capacity(). Returns a zero-length array when empty. This is how the contents are handed to ordinary Fortran routines; note that it is the one operation here that does allocate, so keep it out of the hot path.

    Arguments

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

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

procedure, public :: at => fixed_array_dp_at

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

    Bounds-checked element access, 1-based. Any index outside 1:size() (including indices that are within the capacity but beyond the live elements) sets value to zero and err to ERROR_VALIDATION. On success err is left untouched.

    Arguments

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

procedure, public :: capacity => fixed_array_dp_capacity

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

    Maximum number of elements, i.e. PIC_FIXED_ARRAY_CAPACITY.

    Arguments

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

    Return Value integer(kind=default_int)

procedure, public :: clear => fixed_array_dp_clear

  • private pure subroutine fixed_array_dp_clear(self)

    Drop every element. The storage itself is untouched, so this is a single integer assignment; the array can be reused immediately.

    Arguments

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

procedure, public :: get_unchecked => fixed_array_dp_get_unchecked

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

    UNCHECKED element access for inner loops: no bounds check at all. The caller is responsible for guaranteeing 1 <= index <= size(), typically by looping over 1, array%size(). Reading an index outside that range returns undefined data. Use at unless the bounds check is measurably in the way.

    Arguments

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

    Return Value real(kind=dp)

procedure, public :: is_empty => fixed_array_dp_is_empty

  • private pure function fixed_array_dp_is_empty(self) result(empty)

    True when no elements are live.

    Arguments

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

    Return Value logical

procedure, public :: is_full => fixed_array_dp_is_full

  • private pure function fixed_array_dp_is_full(self) result(full)

    True when a further push_back would fail.

    Arguments

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

    Return Value logical

procedure, public :: pop_back => fixed_array_dp_pop_back

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

    Remove and return the last element (LIFO). On an empty array value is set to zero and err is set to ERROR_VALIDATION. On success err is left untouched.

    Arguments

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

procedure, public :: push_back => fixed_array_dp_push_back

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

    Append an element. If the array is already at capacity the element is not stored, the size is left unchanged and err is set to ERROR_VALIDATION. On success err is left untouched.

    Arguments

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

procedure, public :: size => fixed_array_dp_size

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

    Number of live elements.

    Arguments

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

    Return Value integer(kind=default_int)

Source Code

   type :: fixed_array_dp_t
      !! Bounded array of `real(dp)` with fixed inline storage.
      integer(default_int), private :: n_items = 0
         !! Number of live elements, always in `0:PIC_FIXED_ARRAY_CAPACITY`
      real(dp), private :: items(PIC_FIXED_ARRAY_CAPACITY)
         !! Inline storage. Deliberately not `allocatable`: no heap, ever.
         !! Elements above `n_items` are undefined and must not be read.
   contains
      procedure :: push_back => fixed_array_dp_push_back
      procedure :: pop_back => fixed_array_dp_pop_back
      procedure :: at => fixed_array_dp_at
      procedure :: get_unchecked => fixed_array_dp_get_unchecked
      procedure :: size => fixed_array_dp_size
      procedure :: capacity => fixed_array_dp_capacity
      procedure :: is_empty => fixed_array_dp_is_empty
      procedure :: is_full => fixed_array_dp_is_full
      procedure :: clear => fixed_array_dp_clear
      procedure :: as_array => fixed_array_dp_as_array
   end type fixed_array_dp_t