VisitableOnceGraph

data class VisitableOnceGraph<T>(graph: Graph<T>, visited: Set<T> = emptySet()) : Graph<T>

An immutable Graph decorator that allows visiting each vertex only once.

Parameters

T

the type of vertices in the graph

Constructors

Link copied to clipboard
constructor(graph: Graph<T>, visited: Set<T> = emptySet())

Properties

Link copied to clipboard
open override val edges: Set<Pair<T, T>>

The set of edges in the graph, represented as pairs of vertices.

Link copied to clipboard
open override val vertices: Set<T>

The set of vertices in the graph.

Link copied to clipboard

Converts a Graph into a VisitableOnceGraph which allows visiting each vertex only once.

Functions

Link copied to clipboard
open override fun addEdge(pair: Pair<T, T>): VisitableOnceGraph<T>

open override fun addEdge(from: T, to: T): VisitableOnceGraph<T>

Adds an edge from one vertex to another.

Link copied to clipboard
open override fun addVertex(value: T): VisitableOnceGraph<T>

Adds a vertex to the graph.

Link copied to clipboard
open override fun getNeighbors(vertex: T): Sequence<T>
Link copied to clipboard
fun visitNeighbors(vertex: T, update: (VisitableOnceGraph<T>) -> Unit): Set<T>

Visits the unvisited neighbors of the specified vertex, marking each vertex as visited.