MONC
Private Member Functions | List of all members
collections_mod::c_insert_generic Interface Reference

Inserts a generic element into the list or places at the end if the index > list size. More...

Private Member Functions

subroutine list_insert_generic (specificlist, data, i, memory_allocation_automatic)
 Inserts an element into the list or places at the end if the index > list size. More...
 

Detailed Description

Inserts a generic element into the list or places at the end if the index > list size.

This has a time complexity of O(n)

Parameters
collectionThe specific list involved
dataPointer to the generic data to insert
indexThe list index to insert to
memory_allocation_automaticWhether the collections API should manage the freeing of memory

Definition at line 251 of file collections.F90.

Member Function/Subroutine Documentation

◆ list_insert_generic()

subroutine collections_mod::c_insert_generic::list_insert_generic ( type(list_type), intent(inout)  specificlist,
class(*), intent(in), pointer  data,
integer, intent(in)  i,
logical, intent(in)  memory_allocation_automatic 
)
private

Inserts an element into the list or places at the end if the index > list size.

Do not call directly from external module, this is called via the appropriate interface

Parameters
specificlistThe specific list involved
dataPointer to the generic data to insert
iThe list index to insert to

Definition at line 2850 of file collections.F90.

2850  type(list_type), intent(inout) :: specificlist
2851  integer, intent(in) :: i
2852  class(*), pointer, intent(in) :: data
2853  logical, intent(in) :: memory_allocation_automatic
2854 
2855  integer ::j
2856  type(listnode_type), pointer :: newnode, node
2857 
2858  allocate(newnode)
2859  newnode%data => data
2860 
2861  j=1
2862  node => specificlist%head
2863  if (associated(node)) then
2864  do while(j .lt. i)
2865  if (.not. associated(node%next)) exit
2866  node => node%next
2867  j=j+1
2868  end do
2869  if (j .eq. i) then
2870  ! Insert node
2871  newnode%next => node
2872  newnode%prev => node%prev
2873  newnode%memory_allocation_automatic=memory_allocation_automatic
2874  if (associated(node%prev)) node%prev%next=>newnode
2875  node%prev => newnode
2876  if (associated(node, target=specificlist%head)) specificlist%head=>newnode
2877  else
2878  ! Ran out of list nodes so add this one onto the end
2879  newnode%prev=>specificlist%tail
2880  if (associated(specificlist%tail)) then
2881  specificlist%tail%next => newnode
2882  end if
2883  specificlist%tail => newnode
2884 
2885  if (associated(specificlist%head) .eqv. .false.) then
2886  specificlist%head=>newnode
2887  end if
2888  end if
2889  else
2890  ! No current list data so set up the list with this node
2891  specificlist%head => newnode
2892  specificlist%tail => newnode
2893  end if
2894  specificlist%size=specificlist%size+1

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