Closed wylswz closed 11 months ago
Would using the adjacency and predecessor maps work for you?
adjacencyMap, _ := g.AdjacencyMap()
for target, edge := adjacencyMap[myVertex] {
// This is an outgoing edge of myVertex.
fmt.Println(edge)
}
predecessorMap, _ := g. PredecessorMap()
for source, edge := predecessorMap[myVertex] {
// This is an ingoing edge of myVertex.
fmt.Println(edge)
}
That computes maps from scratch every time, still get O(V+E) time complexity
for _, vertex := range vertices {
m[vertex] = make(map[K]Edge[K])
}
for _, edge := range edges {
m[edge.Source][edge.Target] = edge
}
I can add some caches for now (given that my graph isn't updated very frequently)
Tested out cached adjMap & predMap solution, that worked fine for me. Thanks for your reply, will close this issue
@wylswz Your suggestion of adding functions like EdgesFrom
is good though, I'm going to dig into it.
Is it possible to add methods like this to Graph[K, T]
Currently I need to fetch all edges, and filter them by Target and Source property, which doesn't seem to scale