collections 1.0.0
COLLECTIONS is a library providing a set of types supporting collections in Fortran.
Loading...
Searching...
No Matches
collections::linked_list Type Reference

Defines a generic, linked-list container. More...

Public Member Functions

procedure, public count => ll_count
 Gets the number of items in the list. More...
 
procedure, public move_to_first => ll_move_to_first
 Moves the current position in the list to the first item. More...
 
procedure, public move_to_last => ll_move_to_last
 Moves the current position in the list to the last item. More...
 
procedure, public next => ll_move_to_next
 Moves to the next item in the list. More...
 
procedure, public previous => ll_move_to_previous
 Moves to the previous item in the list. More...
 
procedure, public get => ll_get
 Gets the current item. More...
 
procedure, public set => ll_set
 Replaces the current item in the list with the supplied item. More...
 
procedure, public push => ll_push
 Pushes an item onto the end of the list. More...
 
procedure, public pop => ll_pop
 Pops an item off the back of the list. More...
 
procedure, public clear => ll_clear
 Clears the entire list. More...
 
final ll_destroy
 Finalizer for the linked_list type responsible for clean-up duties when the list goes out of scope. More...
 

Detailed Description

Defines a generic, linked-list container.

Example
The following example illustrates basic usage of the linked_list.
program linked_list_example
use iso_fortran_env
implicit none
! Variables
integer(int32), parameter :: n = 10
integer(int32) :: i
logical :: check
type(linked_list) :: x
class(*), pointer :: ptr
! Create a list
do i = 1, n
call x%push(i)
end do
! Print it out
print '(A)', "***** Original List *****"
check = .true.
do while (check)
ptr => x%get()
! The list uses unlimited polymorphic types; therefore, we need to
! use the select type construct.
select type (ptr)
type is (integer(int32))
print *, ptr
end select
! Move to the next item
check = x%next()
end do
! Print out the item at the current iterator position
print '(A)', new_line('a') // "***** Current Iterator Position *****"
ptr => x%get()
select type(ptr)
type is (integer(int32))
print *, ptr
end select
! Move to the beginning of the collection
print '(A)', new_line('a') // "***** Beginning *****"
call x%move_to_first()
ptr => x%get()
select type (ptr)
type is (integer(int32))
print *, ptr
end select
end program
A module containing various collections using Fortran's unlimited polymorphic functionallity.
Definition: collections.f90:93
The above program generates the following output.
***** Original List *****
1
2
3
4
5
6
7
8
9
10
***** Current Iterator Position *****
10
***** Beginning *****
1

Definition at line 576 of file collections.f90.

Member Function/Subroutine Documentation

◆ clear()

procedure, public collections::linked_list::clear

Clears the entire list.

Syntax
subroutine clear(class(linked_list) this)
Parameters
[in,out]thisThe linked_list object.

Definition at line 712 of file collections.f90.

◆ count()

procedure, public collections::linked_list::count

Gets the number of items in the list.

Syntax
integer(int32) function count(class(linked_list) this)
Parameters
[in]thisThe linked_list object.
Returns
The number of items in the list.

Definition at line 595 of file collections.f90.

◆ get()

procedure, public collections::linked_list::get

Gets the current item.

Syntax
class(*) pointer function get(class(linked_list) this)
Parameters
[in]thisThe linked_list object.
Returns
The currently referenced item from the list. This may be null if the list is empty.

Definition at line 648 of file collections.f90.

◆ ll_destroy()

final collections::linked_list::ll_destroy
final

Finalizer for the linked_list type responsible for clean-up duties when the list goes out of scope.

Definition at line 715 of file collections.f90.

◆ move_to_first()

procedure, public collections::linked_list::move_to_first

Moves the current position in the list to the first item.

Syntax
subroutine move_to_first(class(linked_list) this)
Parameters
[in,out]thisThe linked_list object.

Definition at line 604 of file collections.f90.

◆ move_to_last()

procedure, public collections::linked_list::move_to_last

Moves the current position in the list to the last item.

Syntax
subroutine move_to_last(class(linked_list) this)
Parameters
[in,out]thisThe linked_list object.

Definition at line 613 of file collections.f90.

◆ next()

procedure, public collections::linked_list::next

Moves to the next item in the list.

Syntax
logical function next(class(linked_list) this)
Parameters
[in,out]thisThe linked_list object.
Returns
Returns true if the move was successful; else, returns false. Typically a false value indicates the end of the list; however, a false value can be encountered if the list is emtpy.

Definition at line 625 of file collections.f90.

◆ pop()

procedure, public collections::linked_list::pop

Pops an item off the back of the list.

Syntax
subroutine pop(class(linked_list) this)
Parameters
[in,out]thisThe linked_list object.

Definition at line 703 of file collections.f90.

◆ previous()

procedure, public collections::linked_list::previous

Moves to the previous item in the list.

Syntax
logical function previous(class(linked_list) this)
Parameters
[in,out]thisThe linked_list object.
Returns
Returns true if the move was successful; else, returns false. Typically a false value indicates the end of the list; however, a false value can be encountered if the list is emtpy.

Definition at line 637 of file collections.f90.

◆ push()

procedure, public collections::linked_list::push

Pushes an item onto the end of the list.

Syntax
subroutine push(class(linked_list) this, class(*) x, optional logical manage, optional class(errors) err)
Parameters
[in,out]thisThe linked_list object.
[in]xThe object to store.
[in]manageAn optional input used to determine if the list should manage memory for this object. If set to true a clone of x is stored and the list will handle management of resources held by the clone. If false, the list will not manage resources held by x and x itself will be stored. Notice, in this manner it is possible for x to go out of scope while the list still persists thereby resulting in a potentially undefined behavior. It is recommended to use the default value of true except for very specific and well controlled edge cases.
[in,out]errAn optional output that can be used to track the error status of the routine. Possible error codes are as follows.
  • FL_NO_ERROR: No error.
  • FL_OUT_OF_MEMORY_ERROR: Memory allocation error.

Definition at line 694 of file collections.f90.

◆ set()

procedure, public collections::linked_list::set

Replaces the current item in the list with the supplied item.

Syntax
subroutine set(class(linked_list) this, class(*) x, optional logical manage, optional class(errors) err)
Parameters
[in,out]thisThe linked_list object.
[in]xThe object to store.
[in]manageAn optional input used to determine if the list should manage memory for this object. If set to true a clone of x is stored and the list will handle management of resources held by the clone. If false, the list will not manage resources held by x and x itself will be stored. Notice, in this manner it is possible for x to go out of scope while the list still persists thereby resulting in a potentially undefined behavior. It is recommended to use the default value of true except for very specific and well controlled edge cases.
[in,out]errAn optional output that can be used to track the error status of the routine. Possible error codes are as follows.
  • FL_NO_ERROR: No error.
  • FL_OUT_OF_MEMORY_ERROR: Memory allocation error.

Definition at line 671 of file collections.f90.


The documentation for this type was generated from the following file: