array_list_mod Module

module~~array_list_mod~~UsesGraph module~array_list_mod array_list_mod module~list_mod list_mod module~list_mod->module~array_list_mod module~ordered_mod ordered_mod module~ordered_mod->module~array_list_mod module~queue_mod queue_mod module~ordered_mod->module~queue_mod module~abstract_container_mod abstract_container_mod module~abstract_container_mod->module~array_list_mod module~abstract_container_mod->module~list_mod module~abstract_container_mod->module~ordered_mod module~iterator_mod iterator_mod module~abstract_container_mod->module~iterator_mod module~deque_mod deque_mod module~abstract_container_mod->module~deque_mod module~iterable_mod iterable_mod module~abstract_container_mod->module~iterable_mod module~iterator_mod->module~array_list_mod module~iterator_mod->module~ordered_mod module~iterator_mod->module~iterable_mod module~deque_mod->module~list_mod module~queue_mod->module~deque_mod module~countable_mod countable_mod module~countable_mod->module~ordered_mod module~iterable_mod->module~ordered_mod module~iterable_mod->module~countable_mod iso_fortran_env iso_fortran_env iso_fortran_env->module~abstract_container_mod
Help

Provides a concrete implementation of the list abstract data type. This implementation, the array_list, stores values in an array and thus fast to read from.

Used By

module~~array_list_mod~~UsedByGraph module~array_list_mod array_list_mod module~multimap_mod multimap_mod module~array_list_mod->module~multimap_mod module~data_set_mod data_set_mod module~array_list_mod->module~data_set_mod module~dictionary_mod dictionary_mod module~array_list_mod->module~dictionary_mod module~data_set_mod->module~dictionary_mod module~dynamic_set_mod dynamic_set_mod module~data_set_mod->module~dynamic_set_mod module~dictionary_mod->module~multimap_mod module~map_mod map_mod module~dictionary_mod->module~map_mod module~multiset_mod multiset_mod module~dynamic_set_mod->module~multiset_mod module~map_mod->module~multimap_mod
Help

Derived Types

type, public, extends(list) :: array_list

Components

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

Type-Bound Procedures

procedure, public :: iter => array_list_iter
procedure, public :: contents_type => array_list_contents_type
procedure, public :: size => array_list_size
procedure, public :: push => array_list_push
procedure, public :: pop => array_list_pop
procedure, public :: peek => array_list_peek
procedure, private :: concat => array_list_concat
procedure, public :: clear => array_list_clear
procedure, public :: pushleft => array_list_push
procedure, public :: pushright => array_list_append
procedure, public :: popleft => array_list_popleft
procedure, public :: popright => array_list_pop
procedure, public :: peekleft => array_list_peekleft
procedure, public :: peekright => array_list_peek
procedure, public :: append => array_list_append
procedure, public :: get => array_list_get
procedure, private :: set_single => array_list_set_single
procedure, private :: set_multiple => array_list_set_multiple
procedure, public :: get_index => array_list_get_index
procedure, public :: get_last_index => array_list_get_last_index
procedure, public :: get_indices => array_list_get_indices
procedure, public :: slice => array_list_slice
procedure, public :: foreach => array_list_foreach
procedure, public :: insert => array_list_insert
procedure, public :: remove => array_list_remove
procedure, public :: remove_last => array_list_remove_last
procedure, public :: 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, public :: has => array_list_has
procedure, public :: sort => array_list_sort
procedure, public :: min => array_list_min
procedure, public :: max => array_list_max
procedure, public :: nearest => array_list_nearest
procedure, public :: sum => array_list_sum
procedure, public :: filter => array_list_filter
procedure, public :: to_array => array_list_to_array

Description

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).


Functions

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.

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.

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

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.


Subroutines

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.