list Derived Type

type, public, abstract, extends(deque) :: list

type~~list~~InheritsGraph type~list 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


An abstract data type representing a list. This is a fully dynamic means of storing data of a single type and comes with many advanced type-bound procedures for manipulating said data. This derived type aims to provide many of the same features found in lists in higher-level languages such as Python

Inherited By

type~~list~~InheritedByGraph type~list list type~array_list array_list type~list->type~array_list
Help

Type-Bound Procedures

procedure(append_sub), public, deferred :: append

Add an item to the end of the list

  • subroutine append_sub(this, item) Prototype

    Arguments

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

    Item to be appended to list

procedure(get_func), public, deferred :: get

Get the item at the specified index

  • pure function get_func(this, element) Prototype

    Arguments

    Type IntentOptional AttributesName
    class(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

procedure(set_single_sub), private, deferred :: set_single

Set the specified element to the specified value

  • subroutine set_single_sub(this, element, item) Prototype

    Arguments

    Type IntentOptional AttributesName
    class(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

procedure(set_multiple_sub), private, deferred :: set_multiple

Set the specified elements to the specified values

  • subroutine set_multiple_sub(this, elements, items) Prototype

    Arguments

    Type IntentOptional AttributesName
    class(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.

generic, public :: set => set_single, set_multiple

Set the value of one or more elements in the list

  • subroutine set_single_sub(this, element, item) Prototype

    Arguments

    Type IntentOptional AttributesName
    class(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

  • subroutine set_multiple_sub(this, elements, items) Prototype

    Arguments

    Type IntentOptional AttributesName
    class(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.

procedure(get_index_func), public, deferred :: get_index

Get the index of the first occurrence of this item in the list

  • pure function get_index_func(this, item) Prototype

    Arguments

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

    Return Value integer

    Position of the first occurrence of item in list

procedure(get_last_index_func), public, deferred :: get_last_index

Get the index of the last occurrence of this item in the list

  • pure function get_last_index_func(this, item) Prototype

    Arguments

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

    Return Value integer

    Position of the last occurrence of item in list

procedure(get_indices_func), public, deferred :: get_indices

Get the indices of all occurrences of this item in the list

  • pure function get_indices_func(this, item) Prototype

    Arguments

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

    Return Value integer, dimension(:),allocatable

    Positions of the all occurrences of item in list

procedure(slice_func), public, deferred :: slice

Returns a list containing the items with indices in the specified range

  • function slice_func(this, start_element, end_element) Prototype

    Arguments

    Type IntentOptional AttributesName
    class(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

    A list containing the elements within the slice.

procedure(foreach_sub), public, deferred :: foreach

Perform the provided procedure on each element of the list

  • subroutine foreach_sub(this, action) Prototype

    Arguments

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

    A procedure to act on each element of the list

procedure(insert_sub), public, deferred :: insert

Add the item to the specified position in the list, moving all succeeding elements forward by one position

  • subroutine insert_sub(this, position, item) Prototype

    Arguments

    Type IntentOptional AttributesName
    class(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

procedure(remove_sub), public, deferred :: remove

Remove the first occurrence of the specified item from the list

  • subroutine remove_sub(this, item) Prototype

    Arguments

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

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

procedure(remove_last_sub), public, deferred :: remove_last

Remove the last occurrence of the specified item from the list

  • subroutine remove_last_sub(this, item) Prototype

    Arguments

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

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

procedure(remove_all_sub), public, deferred :: remove_all

Remove the all occurrences of the specified item from the list

  • subroutine remove_all_sub(this, item) Prototype

    Arguments

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

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

procedure(delete_single_sub), private, deferred :: delete_single

Remove the item from the list at the specified index

  • subroutine delete_single_sub(this, element) Prototype

    Arguments

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

    The position of the element to be deleted from the list

procedure(delete_multiple_sub), private, deferred :: delete_multiple

Remove the items from the list at the specified indices

  • subroutine delete_multiple_sub(this, element) Prototype

    Arguments

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

    The positions of the elements to be deleted from the list

procedure(delete_slice_sub), private, deferred :: delete_slice

Remove the items from the list within the specified slice

  • subroutine delete_slice_sub(this, start_element, end_element) Prototype

    Arguments

    Type IntentOptional AttributesName
    class(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

generic, public :: delete => delete_single, delete_multiple, delete_slice

Remove one or more elements from the list

  • subroutine delete_single_sub(this, element) Prototype

    Arguments

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

    The position of the element to be deleted from the list

  • subroutine delete_multiple_sub(this, element) Prototype

    Arguments

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

    The positions of the elements to be deleted from the list

  • subroutine delete_slice_sub(this, start_element, end_element) Prototype

    Arguments

    Type IntentOptional AttributesName
    class(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

procedure(has_func), public, deferred :: has

Returns .true. if the specified item is present in the list.

  • elemental function has_func(this, item) Prototype

    Arguments

    Type IntentOptional AttributesName
    class(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

procedure(sort_sub), public, deferred :: sort

Sorts the list in place using the provided comparison procedure

  • subroutine sort_sub(this, comparison) Prototype

    Arguments

    Type IntentOptional AttributesName
    class(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

procedure(min_func), public, deferred :: min

Returns the smallest item in the list as determined using the provided comparison procedure

  • pure function min_func(this, comparison) Prototype

    Arguments

    Type IntentOptional AttributesName
    class(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

procedure(max_func), public, deferred :: max

Returns the largest item in the list as determined using the provided comparison procedure

  • pure function max_func(this, comparison) Prototype

    Arguments

    Type IntentOptional AttributesName
    class(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

procedure(nearest_func), public, deferred :: nearest

Returns the item in the list for which the provided subtraction procedure returns the smallest absolute value

  • pure function nearest_func(this, item, subtraction) Prototype

    Arguments

    Type IntentOptional AttributesName
    class(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

procedure(sum_func), public, deferred :: sum

Returns an item representing the sum as determined by iteratively applying the provided addition procedure to all elements in the list

  • pure function sum_func(this, addition) Prototype

    Arguments

    Type IntentOptional AttributesName
    class(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

procedure(filter_func), public, deferred :: filter

Returns a list containing all elements from this list for which the provided test procedure returns .true.

  • pure function filter_func(this, test) Prototype

    Arguments

    Type IntentOptional AttributesName
    class(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.

procedure(to_array_func), public, deferred :: to_array

Returns an array of containers holding the contents of this list.

  • pure function to_array_func(this) Prototype

    Arguments

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

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

    An array of container objects holding the contents of this list

Source Code

  type, abstract, extends(deque), public :: list
    !* Author: Chris MacMackin
    !  Date: March 2016
    !
    ! An abstract data type representing a list. This is a fully dynamic
    ! means of storing data of a single type and comes with many advanced
    ! type-bound procedures for manipulating said data. This derived type
    ! aims to provide many of the same features found in lists in 
    ! higher-level languages such as Python
    !
  contains
    procedure(append_sub), deferred :: append
      !! Add an item to the end of the list
    procedure(get_func), deferred :: get
      !! Get the item at the specified index
    procedure(set_single_sub), deferred, private :: set_single
      !! Set the specified element to the specified value
    procedure(set_multiple_sub), deferred, private :: set_multiple
      !! Set the specified elements to the specified values
    generic :: set => set_single, set_multiple
      !! Set the value of one or more elements in the list
    procedure(get_index_func), deferred :: get_index
      !! Get the index of the first occurrence of this item in the list
    procedure(get_last_index_func), deferred :: get_last_index
      !! Get the index of the last occurrence of this item in the list
    procedure(get_indices_func), deferred :: get_indices
      !! Get the indices of all occurrences of this item in the list
    procedure(slice_func), deferred :: slice
      !! Returns a list containing the items with indices in the
      !! specified range
    procedure(foreach_sub), deferred :: foreach
      !! Perform the provided procedure on each element of the list
    procedure(insert_sub), deferred :: insert
      !! Add the item to the specified position in the list, moving
      !! all succeeding elements forward by one position
    procedure(remove_sub), deferred :: remove
      !! Remove the first occurrence of the specified item from the list
    procedure(remove_last_sub), deferred :: remove_last
      !! Remove the last occurrence of the specified item from the list
    procedure(remove_all_sub), deferred :: remove_all
      !! Remove the all occurrences of the specified item from the list
    procedure(delete_single_sub), deferred, private :: delete_single
      !! Remove the item from the list at the specified index
    procedure(delete_multiple_sub), deferred, private :: delete_multiple
      !! Remove the items from the list at the specified indices
    procedure(delete_slice_sub), deferred, private :: delete_slice
      !! Remove the items from the list within the specified slice
    generic :: delete => delete_single, delete_multiple, delete_slice
      !! Remove one or more elements from the list
    procedure(has_func), deferred :: has
      !! Returns `.true.` if the specified item is present in the list.
    procedure(sort_sub), deferred :: sort
      !! Sorts the list in place using the provided comparison procedure
    procedure(min_func), deferred :: min
      !! Returns the smallest item in the list as determined using the
      !! provided comparison procedure
    procedure(max_func), deferred :: max
      !! Returns the largest item in the list as determined using the
      !! provided comparison procedure
    procedure(nearest_func), deferred :: nearest
      !! Returns the item in the list for which the provided subtraction
      !! procedure returns the smallest absolute value
    procedure(sum_func), deferred :: sum
      !! Returns an item representing the sum as determined by
      !! iteratively applying the provided addition procedure to all
      !! elements in the list
    procedure(filter_func), deferred :: filter
      !! Returns a list containing all elements from this list for which
      !! the provided test procedure returns `.true.`
    procedure(to_array_func), deferred :: to_array
      !! Returns an array of containers holding the contents of this
      !! list.
  end type list