-
Notifications
You must be signed in to change notification settings - Fork 47
Open
Labels
Description
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
}