array_list Derived Type

type, public, extends(list) :: array_list

type~~array_list~~InheritsGraph type~array_list array_list type~container container type~container->type~array_list contents type~list list type~list->type~array_list type~deque deque type~deque->type~list type~queue queue type~queue->type~deque type~ordered ordered type~ordered->type~queue type~countable countable type~countable->type~ordered type~iterable iterable type~iterable->type~countable
Help


A concrete implementation of the list abstract data type. This implementation stores list contents in an array. It is fast to read from, but it is slow to insert elements into the middle of the list or to add new items to the end (if doing so requires the storage array to be expanded).

Note that this list is 1-indexed and that all slices are inclusive. In this regard, they are similar to arrays and strings in Fortran.


Components

TypeVisibility AttributesNameInitial
class(container), private, allocatable, dimension(:):: contents
integer, private :: length

Type-Bound Procedures

procedure, public :: iter => array_list_iter

  • private pure function array_list_iter(this)

    Arguments

    Type IntentOptional AttributesName
    class(array_list), intent(in) :: this

    Return Value type(iterator)

    Description

    Author
    Chris MacMackin
    Date
    March 2016

    Returns an iterator containing the contents of this list as they were at the time this method was called.

procedure, public :: contents_type => array_list_contents_type

  • private pure function array_list_contents_type(this) result(cont)

    Arguments

    Type IntentOptional AttributesName
    class(array_list), intent(in) :: this

    Return Value class(container), allocatable

    Description

    Author
    Chris MacMackin
    Date
    March 2016

    Returns a container with the dynamic type of the contents of this list.

procedure, public :: size => array_list_size

  • private pure function array_list_size(this)

    Arguments

    Type IntentOptional AttributesName
    class(array_list), intent(in) :: this

    Return Value integer

    Description

    Author
    Chris MacMackin
    Date
    March 2016

    Returns the number of items in the list

procedure, public :: push => array_list_push

  • private pure subroutine array_list_push(this, item)

    Arguments

    Type IntentOptional AttributesName
    class(array_list), intent(inout) :: this
    class(*), intent(in) :: item

    The value to place at the start of the list.

    Description

    Author
    Chris MacMackin
    Date
    March 2016

    Adds an item to the beginning of the list.

procedure, public :: pop => array_list_pop

  • private function array_list_pop(this) result(pop)

    Arguments

    Type IntentOptional AttributesName
    class(array_list), intent(inout) :: this

    Return Value class(container), allocatable

    The value from the end of the list

    Description

    Author
    Chris MacMackin
    Date
    March 2016

    Removes the item at the end of the list and returns it.

procedure, public :: peek => array_list_peek

  • private pure function array_list_peek(this) result(peek)

    Arguments

    Type IntentOptional AttributesName
    class(array_list), intent(in) :: this

    Return Value class(container), allocatable

    The element at the end of the list

    Description

    Author
    Chris MacMackin
    Date
    March 2016

    Returns the item at the end of the list, without removing it.

procedure, private :: concat => array_list_concat

  • private pure function array_list_concat(lhs, rhs) result(concat)

    Arguments

    Type IntentOptional AttributesName
    class(array_list), intent(in) :: lhs

    The list

    class(ordered), intent(in) :: rhs

    The object being concatenated to the list

    Return Value class(ordered), allocatable

    The concatenated object. Will have dynamic type array_list.

    Description

    Author
    Chris MacMackin
    Date
    March 2016

    Join this list with an ordered object, returning the result. The contents of the returned object are ordered such that applying pop until it is empty would return items in the same order as calling pop until the list is empty and then until the second object is empty.

procedure, public :: clear => array_list_clear

  • private pure subroutine array_list_clear(this)

    Arguments

    Type IntentOptional AttributesName
    class(array_list), intent(inout) :: this

    Description

    Author
    Chris MacMackin
    Date
    March 2016

    Removes all items from this list, but does not change its container type.

procedure, public :: pushleft => array_list_push

  • private pure subroutine array_list_push(this, item)

    Arguments

    Type IntentOptional AttributesName
    class(array_list), intent(inout) :: this
    class(*), intent(in) :: item

    The value to place at the start of the list.

    Description

    Author
    Chris MacMackin
    Date
    March 2016

    Adds an item to the beginning of the list.

procedure, public :: pushright => array_list_append

  • private pure subroutine array_list_append(this, item)

    Arguments

    Type IntentOptional AttributesName
    class(array_list), intent(inout) :: this
    class(*), intent(in) :: item

    Item to be appended to list

    Description

    Author
    Chris MacMackin
    Date
    March 2016

    Adds the provided item to the end of the list.

procedure, public :: popleft => array_list_popleft

  • private function array_list_popleft(this) result(pop)

    Arguments

    Type IntentOptional AttributesName
    class(array_list), intent(inout) :: this

    Return Value class(container), allocatable

    The item just removed from the start of the list

    Description

    Author
    Chris MacMackin
    Date
    March 2016

    Removes the item at the start of the list and returns it.

procedure, public :: popright => array_list_pop

  • private function array_list_pop(this) result(pop)

    Arguments

    Type IntentOptional AttributesName
    class(array_list), intent(inout) :: this

    Return Value class(container), allocatable

    The value from the end of the list

    Description

    Author
    Chris MacMackin
    Date
    March 2016

    Removes the item at the end of the list and returns it.

procedure, public :: peekleft => array_list_peekleft

  • private pure function array_list_peekleft(this) result(peek)

    Arguments

    Type IntentOptional AttributesName
    class(array_list), intent(in) :: this

    Return Value class(container), allocatable

    The item at the start of the list

    Description

    Author
    Chris MacMackin
    Date
    March 2016

    Returns the item at the start of the list.

procedure, public :: peekright => array_list_peek

  • private pure function array_list_peek(this) result(peek)

    Arguments

    Type IntentOptional AttributesName
    class(array_list), intent(in) :: this

    Return Value class(container), allocatable

    The element at the end of the list

    Description

    Author
    Chris MacMackin
    Date
    March 2016

    Returns the item at the end of the list, without removing it.

procedure, public :: append => array_list_append

  • private pure subroutine array_list_append(this, item)

    Arguments

    Type IntentOptional AttributesName
    class(array_list), intent(inout) :: this
    class(*), intent(in) :: item

    Item to be appended to list

    Description

    Author
    Chris MacMackin
    Date
    March 2016

    Adds the provided item to the end of the list.

procedure, public :: get => array_list_get

  • private pure function array_list_get(this, element)

    Arguments

    Type IntentOptional AttributesName
    class(array_list), intent(in) :: this
    integer, intent(in) :: element

    The index (starting from 1) of the element to return

    Return Value class(container), allocatable

    The item with index element. Unallocated if no such element is present.

    Description

    Author
    Chris MacMackin
    Date
    March 2016

    Returns the item at the specified location in the list. Returns an unallocated container if that location has not been set.

procedure, private :: set_single => array_list_set_single

  • private subroutine array_list_set_single(this, element, item)

    Arguments

    Type IntentOptional AttributesName
    class(array_list), intent(inout) :: this
    integer, intent(in) :: element

    The index (starting from 1) of the element whose value is to be set.

    class(*), intent(in) :: item

    The value to store in the specified element

    Description

    Author
    Chris MacMackin
    Date
    March 2016

    Places the value of the provided element in the specified location in the array. Crashes if this element is not already defined.

procedure, private :: set_multiple => array_list_set_multiple

  • private subroutine array_list_set_multiple(this, elements, items)

    Arguments

    Type IntentOptional AttributesName
    class(array_list), intent(inout) :: this
    integer, intent(in), dimension(:):: elements

    The indices (starting from 1) of the elements whose values are to be set.

    class(*), intent(in), dimension(:):: items

    The values to be stored in the specified elements. Each item is placed in the element specified by the integer in the corresponding position in the array elements.

    Description

    Author
    Chris MacMackin
    Date
    March 2016

    Places the values of the provided array of items in the locations specified by the corresponding indices in the in the array of elements.

procedure, public :: get_index => array_list_get_index

  • private pure function array_list_get_index(this, item)

    Arguments

    Type IntentOptional AttributesName
    class(array_list), intent(in) :: this
    class(*), intent(in) :: item

    Return Value integer

    Position of the first occurrence of item in list

    Description

    Author
    Chris MacMackin
    Date
    March 2016

    Returns the index of the first occurrence of the item in the list. If there are no occurrences, then returns -1.

procedure, public :: get_last_index => array_list_get_last_index

  • private pure function array_list_get_last_index(this, item)

    Arguments

    Type IntentOptional AttributesName
    class(array_list), intent(in) :: this
    class(*), intent(in) :: item

    Return Value integer

    Position of the last occurrence of item in list. -1 if item not present

    Description

    Author
    Chris MacMackin
    Date
    March 2016

    Returns the index of the last occurrence of the item in the list. If there are no occurrences, then returns -1.

procedure, public :: get_indices => array_list_get_indices

  • private pure function array_list_get_indices(this, item)

    Arguments

    Type IntentOptional AttributesName
    class(array_list), intent(in) :: this
    class(*), intent(in) :: item

    Return Value integer, dimension(:),allocatable

    Positions of the all occurrences of item in list. Unallocated if item not present.

    Description

    Author
    Chris MacMackin
    Date
    March 2016

    Returns an array containing the indices of all occurrences of the item in the list. If there are no occurrences, then returns an unallocated array.

procedure, public :: slice => array_list_slice

  • private function array_list_slice(this, start_element, end_element)

    Arguments

    Type IntentOptional AttributesName
    class(array_list), intent(in) :: this
    integer, intent(in) :: start_element

    The index of the first element in the slice to be returned

    integer, intent(in) :: end_element

    The index of the last element in the slice to be returned

    Return Value class(list), allocatable

    An array_list containing the elements within the slice.

    Description

    Author
    Chris MacMackin
    Date
    March 2016

    Returns an array_list instance containing all items in this list within the specified slice, inclusive. Crashes if one of the indices is outside of the list's bounds.

procedure, public :: foreach => array_list_foreach

  • private subroutine array_list_foreach(this, action)

    Arguments

    Type IntentOptional AttributesName
    class(array_list), intent(inout) :: this
    procedure(action_sub) :: action

    A procedure to act on each element of the list

    Description

    Author
    Chris MacMackin
    Date
    March 2016

    Performs the specified action on each item in the list, in place.

procedure, public :: insert => array_list_insert

  • private subroutine array_list_insert(this, position, item)

    Arguments

    Type IntentOptional AttributesName
    class(array_list), intent(inout) :: this
    integer, intent(in) :: position

    The location at which the new element will be placed

    class(*), intent(in) :: item

    The value to be placed in the list

    Description

    Author
    Chris MacMackin
    Date
    March 2016

    Places the provided item into the list at the position specified, moving all succeeding items forward by one. The position must be one which is already filled or the length of the list plus one.

procedure, public :: remove => array_list_remove

  • private subroutine array_list_remove(this, item)

    Arguments

    Type IntentOptional AttributesName
    class(array_list), intent(inout) :: this
    class(*), intent(in) :: item

    An item, the first occurrence of which will be removed from the list

    Description

    Author
    Chris MacMackin
    Date
    March 2016

    Remove the first occurrence of the specified item from the list, moving all succeeding items back by one position. No action is taken if the item is not present.

procedure, public :: remove_last => array_list_remove_last

  • private subroutine array_list_remove_last(this, item)

    Arguments

    Type IntentOptional AttributesName
    class(array_list), intent(inout) :: this
    class(*), intent(in) :: item

    An item, the last occurrence of which will be removed from the list

    Description

    Author
    Chris MacMackin
    Date
    March 2016

    Remove the last occurrence of the specified item from the list, moving all succeeding items back by one position. No action is taken if the item is not present.

procedure, public :: remove_all => array_list_remove_all

  • private subroutine array_list_remove_all(this, item)

    Arguments

    Type IntentOptional AttributesName
    class(array_list), intent(inout) :: this
    class(*), intent(in) :: item

    An item, all occurrences of which will be removed from the list

    Description

    Author
    Chris MacMackin
    Date
    March 2016

    Remove all occurrences of the specified item from the list, moving all succeeding items back in position. No action is taken if the item is not present.

procedure, private :: delete_single => array_list_delete_single

  • private subroutine array_list_delete_single(this, element)

    Arguments

    Type IntentOptional AttributesName
    class(array_list), intent(inout) :: this
    integer, intent(in) :: element

    The position of the element to be deleted from the list

    Description

    Author
    Chris MacMackin
    Date
    March 2016

    Removes the element at the specified position in the list, moving all succeeding items back by one position. Crashes if the element has not been set.

procedure, private :: delete_multiple => array_list_delete_multiple

  • private subroutine array_list_delete_multiple(this, element)

    Arguments

    Type IntentOptional AttributesName
    class(array_list), intent(inout) :: this
    integer, intent(in), dimension(:):: element

    The positions of the elements to be deleted from the list

    Description

    Author
    Chris MacMackin
    Date
    March 2016

    Removes the elements at the positions specified by the indices in the array elements from the list. The elements removed are those at the specified location just before the call was made. Once all removals have been performed, the remaining elements well be moved backwards in position as necessary. Crashes if an element has not been set.

procedure, private :: delete_slice => array_list_delete_slice

  • private subroutine array_list_delete_slice(this, start_element, end_element)

    Arguments

    Type IntentOptional AttributesName
    class(array_list), intent(inout) :: this
    integer, intent(in) :: start_element

    Index of the first element in the slice to be deleted

    integer, intent(in) :: end_element

    Index of the last element in the slice to be deleted

    Description

    Author
    Chris MacMackin
    Date
    March 2016

    Removes the element within the specified slice of the list, moving all succeeding items back by the number of items deleted. The slice contains the element at the start index to the end index, inclusive. Crashes if part of the slice has not been set.

procedure, public :: has => array_list_has

  • private elemental function array_list_has(this, item)

    Arguments

    Type IntentOptional AttributesName
    class(array_list), intent(in) :: this
    class(*), intent(in) :: item

    A value whose presence in the list is being checked for

    Return Value logical

    .true. if item is present in list, .false. otherwise

    Description

    Author
    Chris MacMackin
    Date
    March 2016

    Indicates whether there are any copies of the specified item present in the list.

procedure, public :: sort => array_list_sort

  • private subroutine array_list_sort(this, comparison)

    Arguments

    Type IntentOptional AttributesName
    class(array_list), intent(inout) :: this
    procedure(comparison_func) :: comparison

    A procedure which evaluates whether a container object is less than, equal to, or greater than another

    Description

    Author
    Chris MacMackin
    Date
    March 2016

    Sorts the list, in place, so that all items are in ascending order according the the provided comparison function.

procedure, public :: min => array_list_min

  • private pure function array_list_min(this, comparison)

    Arguments

    Type IntentOptional AttributesName
    class(array_list), intent(in) :: this
    procedure(comparison_func) :: comparison

    A procedure which evaluates whether a container object is less than, equal to, or greater than another

    Return Value class(container), allocatable

    The smallest item in the list, as determined by the comparison function

    Description

    Author
    Chris MacMackin
    Date
    March 2016

    Returns the smallest item contained in the list, as determined using the provided comparison function.

procedure, public :: max => array_list_max

  • private pure function array_list_max(this, comparison)

    Arguments

    Type IntentOptional AttributesName
    class(array_list), intent(in) :: this
    procedure(comparison_func) :: comparison

    A procedure which evaluates whether a container object is less than, equal to, or greater than another

    Return Value class(container), allocatable

    The largest item in the list, as determined by the comparison function

    Description

    Author
    Chris MacMackin
    Date
    March 2016

    Returns the largest item contained in the list, as determined using the provided comparison function.

procedure, public :: nearest => array_list_nearest

  • private pure function array_list_nearest(this, item, subtraction)

    Arguments

    Type IntentOptional AttributesName
    class(array_list), intent(in) :: this
    class(*), intent(in) :: item

    The value which those in the list are being compared to

    procedure(subtraction_func) :: subtraction

    A function determining the magnitude of the difference between two items

    Return Value class(container), allocatable

    The value from the list which, when passed to subtraction with item as the other argument, returns the smallest value

    Description

    Author
    Chris MacMackin
    Date
    March 2016

    Returns the value contained in the list for which the subtraction function returns the smallest absolute real number when comparing with the specified item.

procedure, public :: sum => array_list_sum

  • private pure function array_list_sum(this, addition)

    Arguments

    Type IntentOptional AttributesName
    class(array_list), intent(in) :: this
    procedure(addition_func) :: addition

    A procedure performing addition between two container objects and returning the result in another container

    Return Value class(container), allocatable

    A container holding the sum of all of the items held within this list

    Description

    Author
    Chris MacMackin
    Date
    March 2016

    Returns a container representing the sum of all items contained in the list. This sum is calculated by repeatedly applying the addition procedure to the list's contents.

procedure, public :: filter => array_list_filter

  • private pure function array_list_filter(this, test)

    Arguments

    Type IntentOptional AttributesName
    class(array_list), intent(in) :: this
    procedure(test_func) :: test

    A test for which the values that pass will be returned in a new list

    Return Value class(list), allocatable

    Contains those items in this list for which test returns .true.

    Description

    Author
    Chris MacMackin
    Date
    March 2016

    Returns a new list containing only those items held in this list which pass the provided test.

procedure, public :: to_array => array_list_to_array

  • private pure function array_list_to_array(this)

    Arguments

    Type IntentOptional AttributesName
    class(array_list), intent(in) :: this

    Return Value class(container), dimension(:),allocatable

    An array of container objects holding the contents of this list

    Description

    Author
    Chris MacMackin
    Date
    March 2016

    Returns copies of all items held in this list, stored within an array of container objects.

Source Code

  type, public, extends(list) :: array_list
    !* Author: Chris MacMackin
    !  Date: March 2016
    !
    ! A concrete implementation of the [[list]] abstract data type.
    ! This implementation stores list contents in an array. It is fast
    ! to read from, but it is slow to insert elements into the middle
    ! of the list or to add new items to the end (if doing so requires
    ! the storage array to be expanded).
    !
    ! Note that this list is 1-indexed and that all slices are 
    ! inclusive. In this regard, they are similar to arrays and strings
    ! in Fortran.
    !
    private
    class(container), allocatable, dimension(:) :: contents
    integer :: length
  contains
    procedure :: iter => array_list_iter
    procedure :: contents_type => array_list_contents_type
    procedure :: size => array_list_size
    procedure :: push => array_list_push
    procedure :: pop => array_list_pop
    procedure :: peek => array_list_peek
    procedure, private :: concat => array_list_concat
    procedure :: clear => array_list_clear
    procedure :: pushleft => array_list_push
    procedure :: pushright => array_list_append
    procedure :: popleft => array_list_popleft
    procedure :: popright => array_list_pop
    procedure :: peekleft => array_list_peekleft
    procedure :: peekright => array_list_peek
    procedure :: append => array_list_append
    procedure :: get => array_list_get
    procedure, private :: set_single  => array_list_set_single
    procedure, private :: set_multiple => array_list_set_multiple
    procedure :: get_index => array_list_get_index
    procedure :: get_last_index => array_list_get_last_index
    procedure :: get_indices => array_list_get_indices
    procedure :: slice => array_list_slice
    procedure :: foreach => array_list_foreach
    procedure :: insert => array_list_insert
    procedure :: remove => array_list_remove
    procedure :: remove_last => array_list_remove_last
    procedure :: remove_all => array_list_remove_all
    procedure, private :: delete_single => array_list_delete_single
    procedure, private :: delete_multiple => array_list_delete_multiple
    procedure, private :: delete_slice => array_list_delete_slice
    procedure :: has => array_list_has
    procedure :: sort => array_list_sort
    procedure :: min => array_list_min
    procedure :: max => array_list_max
    procedure :: nearest => array_list_nearest
    procedure :: sum => array_list_sum
    procedure :: filter => array_list_filter
    procedure :: to_array => array_list_to_array
  end type array_list