Skip to content

Add Environment.nodesReachableFrom(Node) #898

@DanySK

Description

@DanySK

There is often the need to build a graph of a network segment connected to a Node. This method does so. Stub idea:

private fun <T> Environment<T, *>.connectedNodes(center: Node<T>): Set<Node<T>> {
    fun locallyConnected(node: Node<T>) = getNeighborhood(node).neighbors.toSet()
    val toVisit = ArrayDeque(locallyConnected(center))
    val visited = mutableSetOf(center)
    val result = mutableSetOf(center)
    while (toVisit.isNotEmpty()) {
        val subject = toVisit.removeFirst()
        visited.add(subject)
        toVisit.addAll(locallyConnected(subject) - visited)
        result.add(subject)
    }
    return result
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions