pic_vector Module

Growable vectors: push_back, pop_back, at, and amortised O(1) growth over heap storage.

Choosing between this and pic_fixed_array

pic_fixed_array stores its elements inside the object, never touches the heap, and stops at PIC_FIXED_ARRAY_CAPACITY. Use it in hot loops and inside OpenMP/OpenACC regions.

pic_vector grows without a compile-time bound, at the cost of allocating. Use it where the final length is not known until the input has been read. The two share a method vocabulary on purpose, so moving between them is mostly a type change – but not entirely, and the differences are the kind that fail quietly:

  • A bounds or underflow failure is ERROR_BOUNDS here and ERROR_VALIDATION in pic_fixed_array. Code that branches on the code stops branching after the swap.
  • pic_fixed_array sets value to zero when at or pop_back fails; here value is intent(out) and left undefined, so a caller that ignores err reads something deterministic before the swap and not after.
  • There is no vector_int_t. fixed_array_int_t holds default_int, which changes width with PIC_DEFAULT_INT8; see below.

Element kinds are fixed width

There is no vector_int_t following default_int: the same source would mean a 32-bit container in one build and a 64-bit one in the other, and anything serialized from it would not survive the switch. Sizes and indices are default_int, as everywhere else in PIC.

Storage is private

Only 1:size() of the backing array is meaningful. Exposing it would let v%items(v%size() + 1) compile and read spare capacity. The two cases that need to avoid a copy are served directly: take moves the storage out, and get_unchecked skips the bounds test.

Usage: type(vector_int32_t) :: v type(error_t) :: err integer(int32), allocatable :: final(:)

call v%push_back(42_int32, err) call v%take(final) ! v is now empty, final is exactly sized


Uses

  • module~~pic_vector~~UsesGraph module~pic_vector pic_vector module~pic_error pic_error module~pic_vector->module~pic_error module~pic_string_type pic_string_type module~pic_vector->module~pic_string_type module~pic_types pic_types module~pic_vector->module~pic_types module~pic_error->module~pic_types module~pic_global_definitions pic_global_definitions module~pic_error->module~pic_global_definitions module~pic_string_type->module~pic_types module~pic_ascii pic_ascii module~pic_string_type->module~pic_ascii module~pic_optional_value pic_optional_value module~pic_string_type->module~pic_optional_value iso_c_binding iso_c_binding module~pic_types->iso_c_binding iso_fortran_env iso_fortran_env module~pic_types->iso_fortran_env module~pic_ascii->module~pic_types module~pic_global_definitions->module~pic_types module~pic_optional_value->module~pic_types

Variables

Type Visibility Attributes Name Initial
integer(kind=default_int), public, parameter :: PIC_VECTOR_MAX_CAPACITY = huge(0_default_int)

Largest representable capacity. Growth clamps here rather than overflowing default_int, and a request beyond it is ERROR_ALLOC.

integer(kind=default_int), public, parameter :: PIC_VECTOR_MIN_CAPACITY = 8_default_int

Capacity of a vector after its first push_back.


Derived Types

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
procedure, public :: as_array => vec_dp_as_array
procedure, public :: at => vec_dp_at
procedure, public :: capacity => vec_dp_capacity
procedure, public :: clear => vec_dp_clear
procedure, public :: destroy => vec_dp_destroy
procedure, public :: get_unchecked => vec_dp_get_unchecked
procedure, public :: is_empty => vec_dp_is_empty
procedure, public :: pop_back => vec_dp_pop_back
procedure, public :: push_back => vec_dp_push_back
procedure, public :: reserve => vec_dp_reserve
procedure, public :: resize => vec_dp_resize
procedure, public :: set => vec_dp_set
procedure, public :: shrink_to_fit => vec_dp_shrink_to_fit
procedure, public :: size => vec_dp_size
procedure, public :: take => vec_dp_take

type, public ::  vector_int32_t

Growable array of integer(int32).

Components

Type Visibility Attributes Name Initial
integer(kind=int32), 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_int32_append
procedure, public :: as_array => vec_int32_as_array
procedure, public :: at => vec_int32_at
procedure, public :: capacity => vec_int32_capacity
procedure, public :: clear => vec_int32_clear
procedure, public :: destroy => vec_int32_destroy
procedure, public :: get_unchecked => vec_int32_get_unchecked
procedure, public :: is_empty => vec_int32_is_empty
procedure, public :: pop_back => vec_int32_pop_back
procedure, public :: push_back => vec_int32_push_back
procedure, public :: reserve => vec_int32_reserve
procedure, public :: resize => vec_int32_resize
procedure, public :: set => vec_int32_set
procedure, public :: shrink_to_fit => vec_int32_shrink_to_fit
procedure, public :: size => vec_int32_size
procedure, public :: take => vec_int32_take

type, public ::  vector_int64_t

Growable array of integer(int64).

Components

Type Visibility Attributes Name Initial
integer(kind=int64), 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_int64_append
procedure, public :: as_array => vec_int64_as_array
procedure, public :: at => vec_int64_at
procedure, public :: capacity => vec_int64_capacity
procedure, public :: clear => vec_int64_clear
procedure, public :: destroy => vec_int64_destroy
procedure, public :: get_unchecked => vec_int64_get_unchecked
procedure, public :: is_empty => vec_int64_is_empty
procedure, public :: pop_back => vec_int64_pop_back
procedure, public :: push_back => vec_int64_push_back
procedure, public :: reserve => vec_int64_reserve
procedure, public :: resize => vec_int64_resize
procedure, public :: set => vec_int64_set
procedure, public :: shrink_to_fit => vec_int64_shrink_to_fit
procedure, public :: size => vec_int64_size
procedure, public :: take => vec_int64_take

type, public ::  vector_string_t

Growable array of type(string_type).

Components

Type Visibility Attributes Name Initial
type(string_type), 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_string_append
procedure, public :: as_array => vec_string_as_array
procedure, public :: at => vec_string_at
procedure, public :: capacity => vec_string_capacity
procedure, public :: clear => vec_string_clear
procedure, public :: destroy => vec_string_destroy
procedure, public :: get_unchecked => vec_string_get_unchecked
procedure, public :: is_empty => vec_string_is_empty
procedure, public :: pop_back => vec_string_pop_back
procedure, public :: push_back => vec_string_push_back
procedure, public :: reserve => vec_string_reserve
procedure, public :: resize => vec_string_resize
procedure, public :: set => vec_string_set
procedure, public :: shrink_to_fit => vec_string_shrink_to_fit
procedure, public :: size => vec_string_size
procedure, public :: take => vec_string_take

Functions

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, (:)

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)

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)

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

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)

private pure function vec_int32_as_array(self) result(copy)

A copy holding exactly size() elements.

Arguments

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

Return Value integer(kind=int32), allocatable, (:)

private pure function vec_int32_capacity(self) result(n)

Elements that fit before the next reallocation.

Arguments

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

Return Value integer(kind=default_int)

private pure function vec_int32_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_int32_t), intent(in) :: self
integer(kind=default_int), intent(in) :: index

Return Value integer(kind=int32)

private pure function vec_int32_is_empty(self) result(flag)

.true. when there are no live elements.

Arguments

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

Return Value logical

private pure function vec_int32_size(self) result(n)

Number of live elements.

Arguments

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

Return Value integer(kind=default_int)

private pure function vec_int64_as_array(self) result(copy)

A copy holding exactly size() elements.

Arguments

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

Return Value integer(kind=int64), allocatable, (:)

private pure function vec_int64_capacity(self) result(n)

Elements that fit before the next reallocation.

Arguments

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

Return Value integer(kind=default_int)

private pure function vec_int64_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_int64_t), intent(in) :: self
integer(kind=default_int), intent(in) :: index

Return Value integer(kind=int64)

private pure function vec_int64_is_empty(self) result(flag)

.true. when there are no live elements.

Arguments

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

Return Value logical

private pure function vec_int64_size(self) result(n)

Number of live elements.

Arguments

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

Return Value integer(kind=default_int)

private pure function vec_string_as_array(self) result(copy)

A copy holding exactly size() elements.

Arguments

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

Return Value type(string_type), allocatable, (:)

private pure function vec_string_capacity(self) result(n)

Elements that fit before the next reallocation.

Arguments

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

Return Value integer(kind=default_int)

private pure function vec_string_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_string_t), intent(in) :: self
integer(kind=default_int), intent(in) :: index

Return Value type(string_type)

private pure function vec_string_is_empty(self) result(flag)

.true. when there are no live elements.

Arguments

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

Return Value logical

private pure function vec_string_size(self) result(n)

Number of live elements.

Arguments

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

Return Value integer(kind=default_int)


Subroutines

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

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

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

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

private pure subroutine vec_dp_grow(self, needed, err)

Ensure capacity for at least needed elements, preserving the live ones. Capacity starts at PIC_VECTOR_MIN_CAPACITY and doubles, which keeps a run of push_back calls amortised O(1).

Arguments

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

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

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

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

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

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

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

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

private pure subroutine vec_int32_append(self, values, err)

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

Arguments

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

private pure subroutine vec_int32_at(self, index, value, err)

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

Arguments

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

private pure subroutine vec_int32_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_int32_t), intent(inout) :: self

private pure subroutine vec_int32_destroy(self)

Release all storage and reset to the empty state.

Arguments

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

private pure subroutine vec_int32_grow(self, needed, err)

Ensure capacity for at least needed elements, preserving the live ones. Capacity starts at PIC_VECTOR_MIN_CAPACITY and doubles, which keeps a run of push_back calls amortised O(1).

Arguments

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

private pure subroutine vec_int32_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_int32_t), intent(inout) :: self
integer(kind=int32), intent(out) :: value
type(error_t), intent(inout), optional :: err

private pure subroutine vec_int32_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_int32_t), intent(inout) :: self
integer(kind=int32), intent(in) :: value
type(error_t), intent(inout), optional :: err

private pure subroutine vec_int32_reserve(self, n, err)

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

Arguments

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

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.

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

private pure subroutine vec_int32_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_int32_t), intent(inout) :: self
integer(kind=default_int), intent(in) :: index
integer(kind=int32), intent(in) :: value
type(error_t), intent(inout), optional :: err

private pure subroutine vec_int32_shrink_to_fit(self, err)

Release capacity beyond size().

Arguments

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

private pure subroutine vec_int32_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_int32_t), intent(inout) :: self
integer(kind=int32), intent(out), allocatable :: array(:)
type(error_t), intent(inout), optional :: err

private pure subroutine vec_int64_append(self, values, err)

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

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

private pure subroutine vec_int64_at(self, index, value, err)

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

Arguments

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

private pure subroutine vec_int64_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_int64_t), intent(inout) :: self

private pure subroutine vec_int64_destroy(self)

Release all storage and reset to the empty state.

Arguments

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

private pure subroutine vec_int64_grow(self, needed, err)

Ensure capacity for at least needed elements, preserving the live ones. Capacity starts at PIC_VECTOR_MIN_CAPACITY and doubles, which keeps a run of push_back calls amortised O(1).

Arguments

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

private pure subroutine vec_int64_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_int64_t), intent(inout) :: self
integer(kind=int64), intent(out) :: value
type(error_t), intent(inout), optional :: err

private pure subroutine vec_int64_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_int64_t), intent(inout) :: self
integer(kind=int64), intent(in) :: value
type(error_t), intent(inout), optional :: err

private pure subroutine vec_int64_reserve(self, n, err)

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

Arguments

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

private pure subroutine vec_int64_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_int64_t), intent(inout) :: self
integer(kind=default_int), intent(in) :: n
integer(kind=int64), intent(in) :: fill
type(error_t), intent(inout), optional :: err

private pure subroutine vec_int64_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_int64_t), intent(inout) :: self
integer(kind=default_int), intent(in) :: index
integer(kind=int64), intent(in) :: value
type(error_t), intent(inout), optional :: err

private pure subroutine vec_int64_shrink_to_fit(self, err)

Release capacity beyond size().

Arguments

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

private pure subroutine vec_int64_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_int64_t), intent(inout) :: self
integer(kind=int64), intent(out), allocatable :: array(:)
type(error_t), intent(inout), optional :: err

private pure subroutine vec_string_append(self, values, err)

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

Arguments

Type IntentOptional Attributes Name
class(vector_string_t), intent(inout) :: self
type(string_type), intent(in) :: values(:)
type(error_t), intent(inout), optional :: err

private pure subroutine vec_string_at(self, index, value, err)

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

Arguments

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

private pure subroutine vec_string_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_string_t), intent(inout) :: self

private pure subroutine vec_string_destroy(self)

Release all storage and reset to the empty state.

Arguments

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

private pure subroutine vec_string_grow(self, needed, err)

Ensure capacity for at least needed elements, preserving the live ones. Capacity starts at PIC_VECTOR_MIN_CAPACITY and doubles, which keeps a run of push_back calls amortised O(1).

Arguments

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

private pure subroutine vec_string_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_string_t), intent(inout) :: self
type(string_type), intent(out) :: value
type(error_t), intent(inout), optional :: err

private pure subroutine vec_string_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_string_t), intent(inout) :: self
type(string_type), intent(in) :: value
type(error_t), intent(inout), optional :: err

private pure subroutine vec_string_reserve(self, n, err)

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

Arguments

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

private pure subroutine vec_string_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_string_t), intent(inout) :: self
integer(kind=default_int), intent(in) :: n
type(string_type), intent(in) :: fill
type(error_t), intent(inout), optional :: err

private pure subroutine vec_string_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_string_t), intent(inout) :: self
integer(kind=default_int), intent(in) :: index
type(string_type), intent(in) :: value
type(error_t), intent(inout), optional :: err

private pure subroutine vec_string_shrink_to_fit(self, err)

Release capacity beyond size().

Arguments

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

private pure subroutine vec_string_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_string_t), intent(inout) :: self
type(string_type), intent(out), allocatable :: array(:)
type(error_t), intent(inout), optional :: err