fdoc

subroutineneighbours_ofprivate

subroutine neighbours_of(p, relation, job, ids)

What is next to the one root of job in its graph: the first entities that describe_graph reaches, in the same order and within the same limit, so that a list of them matches the drawing.

Arguments

NameTypeIntentAttributesDescription
ptype(project_t)in

the project

relationtype(adjacency_t)in

the relation

jobtype(graph_job_t)in

the graph

idsintegeroutallocatabledimension(:)

the entities next to the root

Calls

  • consider

Called by

Source

Show the code
subroutine neighbours_of(p, relation, job, ids)
    type(project_t), intent(in) :: p                !! the project
    type(adjacency_t), intent(in) :: relation       !! the relation
    type(graph_job_t), intent(in) :: job            !! the graph
    integer, allocatable, intent(out) :: ids(:)     !! the entities next to the root
    integer :: j, other, root

    allocate (ids(0))
    root = job%roots(1)
    if (job%max_depth < 1) return
    if (job%forward) then
        if (.not. allocated(relation%out(root)%ids)) return
        do j = 1, size(relation%out(root)%ids)
            call consider(relation%out(root)%ids(j))
        end do
    else
        if (.not. allocated(relation%in(root)%ids)) return
        do j = 1, size(relation%in(root)%ids)
            call consider(relation%in(root)%ids(j))
        end do
    end if

contains

    !> Add `other` if the graph has room for it.
    subroutine consider(item)
        integer, intent(in) :: item     !! the entity

        other = item
        if (other == root .or. p%list%box(other)%e%kind == E_NONE) return
        if (any(ids == other)) return
        if (size(ids) + 1 >= job%max_nodes) return
        call push_int(ids, other)
    end subroutine consider

end subroutine neighbours_of