(patch) add incoming edges
All checks were successful
/ Build and Test Library Snapshot (pull_request) Successful in 2m16s
All checks were successful
/ Build and Test Library Snapshot (pull_request) Successful in 2m16s
This commit is contained in:
parent
5827a13f21
commit
4eb2f3971a
2 changed files with 21 additions and 0 deletions
|
|
@ -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}")
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue