rDynamicArray_Class Module

module~~rdynamicarray_class~~UsesGraph module~rdynamicarray_class rDynamicArray_Class module~variablekind variableKind module~variablekind->module~rdynamicarray_class module~m_sort m_sort module~variablekind->module~m_sort module~m_strings m_strings module~variablekind->module~m_strings module~m_errors m_errors module~variablekind->module~m_errors module~m_allocate m_allocate module~variablekind->module~m_allocate module~m_searching m_searching module~variablekind->module~m_searching module~m_deallocate m_deallocate module~variablekind->module~m_deallocate module~m_reallocate m_reallocate module~variablekind->module~m_reallocate module~m_parameters m_parameters module~variablekind->module~m_parameters module~m_unittester m_unitTester module~variablekind->module~m_unittester module~m_sort->module~rdynamicarray_class module~m_strings->module~rdynamicarray_class module~m_errors->module~rdynamicarray_class module~m_errors->module~m_strings module~m_errors->module~m_allocate module~m_errors->module~m_deallocate module~m_errors->module~m_reallocate module~m_errors->module~m_unittester module~m_allocate->module~rdynamicarray_class module~m_allocate->module~m_reallocate module~m_searching->module~rdynamicarray_class module~m_deallocate->module~rdynamicarray_class module~m_reallocate->module~rdynamicarray_class iso_fortran_env iso_fortran_env iso_fortran_env->module~variablekind iso_fortran_env->module~m_strings iso_fortran_env->module~m_errors iso_fortran_env->module~m_unittester module~m_parameters->module~m_strings module~m_unittester->module~m_allocate
Help

Class that act as stacks, queues, and priority queues. These classes use dynamically allocated contiguous blocks of memory to store a list of numbers. The queues can be sorted to become priority queues and use binary searches to quickly insert new numbers. If the allocated memory is filled, the available space is doubled. Memory is only reallocated to a smaller size, if the utilization is a quarter of that allocated.

program dynamicArray_test
use variableKind, only: i32
use rDynamicArray_Class, only: rDynamicArray

implicit none

type(rDynamicArray) :: da, da2
integer(i32) :: ia

da = rDynamicArray(10)
call da%insertAt(1, 10.0)
call da%insertAt(1, 20.0)
call da%prepend(30.0)
call da%append(40.0)
call da%remove(2)
call da%tighten()
da2 = da
da2%values(2) = 50.0
call da%deallocate()
call da2%deallocate()

da = rDynamicArray(3, sorted=.true.)
call da%insertSorted(20.0)
call da%insertSorted(30.0)
call da%insertSorted(10.0)
ia = da%locationOf(20.0)
call da%insertSortedUnique(10.0)
call da%insertSortedUnique(15.0)
call da%deallocate()

da = rDynamicArray(3, sorted=.true., fixed=.true.)
call da%insertSorted(20.0)
call da%insertSorted(30.0)
call da%insertSorted(10.0)
ia = da%locationOf(20.0)
call da%insertSortedUnique(10.0)
call da%insertSortedUnique(15.0)
call da%deallocate()
end program

Used By

module~~rdynamicarray_class~~UsedByGraph module~rdynamicarray_class rDynamicArray_Class module~m_tests m_tests module~rdynamicarray_class->module~m_tests module~rargdynamicarray_class rArgDynamicArray_Class module~rdynamicarray_class->module~rargdynamicarray_class program~test_coretran test_coretran module~m_tests->program~test_coretran module~rargdynamicarray_class->module~m_tests
Help


Interfaces

public interface rDynamicArray

  • private function init_rDynamicArray_i1(M, sorted, fixed) result(this)

    Overloaded by interface rDynamicArray()

    Arguments

    Type IntentOptional AttributesName
    integer(kind=i32), intent(in), optional :: M

    Amount of memory to allocate.

    logical, intent(in), optional :: sorted

    Maintain a sorted array.

    logical, intent(in), optional :: fixed

    Maintain a fixed size array.

    Return Value type(rDynamicArray)

    Return type.

  • private function init_rDynamicArray_d1D(values, M, sorted, fixed) result(this)

    Overloaded by interface rDynamicArray()

    Arguments

    Type IntentOptional AttributesName
    real(kind=r32), intent(in) :: values(:)

    Set of values to initialize with.

    integer(kind=i32), intent(in), optional :: M

    Amount of memory to allocate.

    logical, intent(in), optional :: sorted

    Maintain a sorted array.

    logical, intent(in), optional :: fixed

    Maintain a fixed size array.

    Return Value type(rDynamicArray)

    Return type


Derived Types

type, public :: rDynamicArray

Class that act as stacks, queues, and priority queues. See rDynamicArray_Class for more information on how to use this class.

Components

TypeVisibility AttributesNameInitial
integer(kind=i32), public :: N

Current size of the array

real(kind=r32), public, allocatable:: values(:)

Memory for values, can be larger than N

logical, public :: sorted =.false.

Keep track of whether the array is sorted for potential speed increases

logical, public :: fixed =.false.

Don't allow the memory to change after initial instantiation.

Constructor

private function init_rDynamicArray_i1(M, sorted, fixed)

Overloaded by interface rDynamicArray()

private function init_rDynamicArray_d1D(values, M, sorted, fixed)

Overloaded by interface rDynamicArray()

Type-Bound Procedures

procedure, public :: append => append_rDynamicArray

rDynamicArray%append() - Append a value to the end of the dynamic array. Will change a sorted dynamic array to unsorted.

procedure, public :: deallocate => deallocate_rDynamicArray

rDynamicArray%deallocate() - Deallocate a dynamic array.

procedure, public :: insertAt => insertAt_rDynamicArray

rDynamicArray%insertAt() - Insert a value at a given index.

procedure, public :: insertSorted => insertSorted_rDynamicArray

rDynamicArray%insertSorted() - Insert a value into a sorted dynamic array.

procedure, public :: insertSortedUnique => insertSortedUnique_rDynamicArray

rDynamicArray%insertSortedUnique() - Inserts only unique numbers into a dynamic array.

procedure, public :: isEmpty => isEmpty_rDynamicArray

rDynamicArray%isEmpty() - True if the array is empty.

procedure, public :: isFilled => isFilled_rDynamicArray

rDynamicArray%isFilled() - True if the array is filled.

procedure, public :: locationOf => locationOf_rDynamicArray

rDynamicArray%locationOf() - Get the location of a value in a sorted dynamic array.

procedure, public :: prepend => prepend_rDynamicArray

rDynamicArray%prepend() - Prepend a value to the start of the dynamic array. Only for unsorted dynamic arrays

procedure, public :: reallocate => reallocate_rDynamicArray

rDynamicArray%reallocate() - Create new contiguous memory to match the needs of the expanding or shrinking array.

procedure, public :: remove => remove_rDynamicArray

rDynamicArray%remove() - Remove an element from the array.

procedure, public :: tighten => tighten_rDynamicArray

rDynamicArray%tighten() - Removes excess buffer memory and trims it to the current length.