All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.io.github.alexandrepiveteau.graphs.UndirectedGraph.traversals.kt Maven / Gradle / Ivy

Go to download

Model directed, undirected, weighted and unweighted graphs and perform computations on them in Kotlin multiplatform.

There is a newer version: 0.6.1
Show newest version
package io.github.alexandrepiveteau.graphs

import kotlin.contracts.contract

/**
 * Performs the given [action] on each edge in this graph.
 *
 * ## Asymptotic complexity
 * - **Time complexity**: O(|E|), where |E| is the number of edges in this graph.
 * - **Space complexity**: O(1).
 */
public inline fun UndirectedGraph.forEachEdge(action: (Edge) -> Unit) {
  contract { callsInPlace(action) }
  forEachVertex { u -> forEachNeighbor(u) { v -> if (u.index <= v.index) action(u edgeTo v) } }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy