Remove a id from ids list.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(dictionary), | intent(inout) | :: | self | The dictionary. |
||
integer(kind=I8P), | intent(in) | :: | id | Unique id to add. |
subroutine remove_id(self, id)
!---------------------------------------------------------------------------------------------------------------------------------
!< Remove a id from ids list.
!---------------------------------------------------------------------------------------------------------------------------------
class(dictionary), intent(inout) :: self !< The dictionary.
integer(I8P), intent(in) :: id !< Unique id to add.
type(dictionary_node), pointer :: p !< Pointer to scan the dictionary.
!---------------------------------------------------------------------------------------------------------------------------------
!---------------------------------------------------------------------------------------------------------------------------------
if (self%nodes_number==1) then
self%ids_ = 0
elseif (self%nodes_number>=2) then
p => null()
if (self%ids_(1)==id) then
call self%traverse_iterator(iterator=id_iterator_search)
if (associated(p)) then
if (associated(p%next)) then
if (p%next%has_key()) then
self%ids_(1) = p%next%key%id()
endif
endif
endif
elseif (self%ids_(2)==id) then
call self%traverse_iterator(iterator=id_iterator_search)
if (associated(p)) then
if (associated(p%previous)) then
if (p%previous%has_key()) then
self%ids_(2) = p%previous%key%id()
endif
endif
endif
endif
endif
!---------------------------------------------------------------------------------------------------------------------------------
contains
subroutine id_iterator_search(node, done)
!-------------------------------------------------------------------------------------------------------------------------------
!< Iterator procedure for searching a id.
!-------------------------------------------------------------------------------------------------------------------------------
type(dictionary_node), pointer, intent(in) :: node !< Actual node pointer in the dictionary.
logical, intent(out) :: done !< Flag to set to true to stop traversing.
!-------------------------------------------------------------------------------------------------------------------------------
!-------------------------------------------------------------------------------------------------------------------------------
done = .false.
if (node%has_key()) done = node%key%id()==id
if (done) p => node
!-------------------------------------------------------------------------------------------------------------------------------
endsubroutine id_iterator_search
endsubroutine remove_id