
commonMain.com.toxicbakery.kfinstatemachine.graph.DirectedGraph.kt Maven / Gradle / Ivy
package com.toxicbakery.kfinstatemachine.graph
/**
* Graph implementation built by defining nodes via their associated edges.
* The graph may contain one or groups of edges.
*
* @param mappedEdges edges of the graph grouped by their left node pointing to `n` nodes
*/
open class DirectedGraph(
private val mappedEdges: Map>
) : IDirectedGraph {
override val nodes: Set =
mappedEdges.values
.flatMap(Map::values)
.plus(mappedEdges.keys)
.toSet()
override fun transitions(node: N): Set =
edges(node).keys
override fun edges(
node: N,
defaultValue: () -> Map
): Map = mappedEdges.getOrElse(node, defaultValue)
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy