(patch) add incoming edges #4

Merged
pfm merged 1 commit from incoming-edges into main 2026-01-08 04:26:53 +00:00
2 changed files with 21 additions and 0 deletions
Showing only changes of commit 4eb2f3971a - Show all commits

View file

@ -51,6 +51,7 @@ lazy val testSettings = Seq(
lazy val `gs-graph` = project lazy val `gs-graph` = project
.in(file(".")) .in(file("."))
.aggregate(core, cats, fs2) .aggregate(core, cats, fs2)
.settings(noPublishSettings)
.settings(sharedSettings) .settings(sharedSettings)
.settings(testSettings) .settings(testSettings)
.settings(name := s"${gsProjectName.value}-v${semVerMajor.value}") .settings(name := s"${gsProjectName.value}-v${semVerMajor.value}")

View file

@ -20,6 +20,26 @@ final class Adjacency(val neighbors: Vector[Vector[Vertex]]):
*/ */
def at(vertex: Vertex): Vector[Vertex] = neighbors(vertex.ordinal) def at(vertex: Vertex): Vector[Vertex] = neighbors(vertex.ordinal)
/** Get the vector of _incoming_ [[Vertex]] that point _to_ some input
* [[Vertex]].
*
* @param vertex
* The [[Vertex]] for which to retrieve the incoming vertices.
* @return
* The list of [[Vertex]] that have an edge _to_ the input [[Vertex]].
*/
def incoming(vertex: Vertex): Vector[Vertex] =
if vertex.ordinal >= neighbors.length then Vector.empty
else
neighbors.zipWithIndex
.filterNot {
// ignore the neighbors of the input vertex
case (_, index) => index != vertex.ordinal
}
.filter(_._1.contains(vertex))
.map(_._2)
.map(Vertex(_))
/** Express this [[Adjacency]] as a vector of [[Edge]]. /** Express this [[Adjacency]] as a vector of [[Edge]].
* *
* @return * @return