append an entry at the end of the integer list If the first entry is zero, write into that one Check, if the current entry already exists Count, how many elements there are in the list
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(tem_longList), | pointer | :: | firstEntry |
linked list of resulting elements building the neighbor |
||
integer(kind=long_k), | intent(in) | :: | entryPos |
Add that element |
||
integer, | intent(inout) | :: | nItems |
how many items are in list |
||
logical, | intent(out), | optional | :: | added |
has the current item been added? |
subroutine tem_appendLongListUnique( firstEntry, entryPos, nItems, added )
! ---------------------------------------------------------------------------
!> linked list of resulting elements building the neighbor
type(tem_longList),pointer :: firstEntry
!> Add that element
integer(kind=long_k),intent(in) :: entryPos
!> how many items are in list
integer,intent(inout) :: nItems
!> has the current item been added?
logical,intent(out),optional :: added
! ---------------------------------------------------------------------------
type(tem_longList),pointer :: currPos ! current position in linked list
logical :: found ! has the new entry been found in the existing list?
! ---------------------------------------------------------------------------
Added = .false.
found = .false.
currPos => firstEntry ! The first entry of the list should be given here
if(currPos%elem .le. 0) then
! If the element entry of the current entry is zero
! write into that position
currPos%elem = entryPos
nItems = 1
Added = .true.
else
! If element entry /= 0 then find the end of the list
do while(associated(currPos%next))
if( currPos%elem .eq. entryPos) found = .true.
currPos => currPos%next
enddo
if( currPos%elem .eq. entryPos) found = .true.
if ( .not. found) then
! at the end of the list, append new list item
allocate(currPos%next)
currPos => currPos%next
! And write to the item
currPos%elem = entryPos
nItems = nItems + 1
endif
endif
end subroutine tem_appendLongListUnique