Remove a node from a dag. Will also remove any edges connected to it.
This will renumber the nodes and edges internally. Note that any default integer labels generated in dag_set_vertices would then be questionable.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
class(dag), | intent(inout) | :: | me | |||
integer(kind=ip), | intent(in) | :: | ivertex |
the node to remove |
subroutine dag_remove_node(me,ivertex) class(dag),intent(inout) :: me integer(ip),intent(in) :: ivertex !! the node to remove integer(ip) :: i !! counter type(vertex),dimension(:),allocatable :: tmp !! for resizing `me%vertices` if (allocated(me%vertices)) then associate (n => size(me%vertices)) do i = 1, n ! first remove any edges: call me%vertices(i)%remove_edge(ivertex) ! next, renumber the existing edges so they will be ! correct after ivertex is deleted ! Example (removing 2): 1 [2] 3 4 ==> 1 2 3 if (allocated(me%vertices(i)%edges)) then where (me%vertices(i)%edges%ivertex>ivertex) me%vertices(i)%edges%ivertex = me%vertices(i)%edges%ivertex - 1 end where end if end do ! now, remove the node: allocate(tmp(n-1)) if (ivertex>1) tmp(1:ivertex-1) = me%vertices(1:ivertex-1) if (ivertex<n) tmp(ivertex:n-1) = me%vertices(ivertex+1:n) call move_alloc(tmp,me%vertices) end associate end if me%n = size(me%vertices) if (me%n==0) deallocate(me%vertices) end subroutine dag_remove_node