GetForwardAdjacentVertices returns all the edges that originate from the given vertex.
(from VertexType)
| 71 | |
| 72 | // GetForwardAdjacentVertices returns all the edges that originate from the given vertex. |
| 73 | func (g *Graph[EdgeType, VertexType]) GetForwardAdjacentVertices(from VertexType) []Edge[EdgeType, VertexType] { |
| 74 | g.mu.RLock() |
| 75 | defer g.mu.RUnlock() |
| 76 | |
| 77 | fromID, exists := g.vertexToID[from] |
| 78 | if !exists { |
| 79 | return []Edge[EdgeType, VertexType]{} |
| 80 | } |
| 81 | |
| 82 | edges := []Edge[EdgeType, VertexType]{} |
| 83 | toNodes := g.gonumGraph.From(fromID) |
| 84 | for toNodes.Next() { |
| 85 | toID := toNodes.Node().ID() |
| 86 | to := g.idToVertex[toID] |
| 87 | |
| 88 | // Get the edge type |
| 89 | edgeKey := fmt.Sprintf("%d->%d", fromID, toID) |
| 90 | edgeType := g.edgeTypes[edgeKey] |
| 91 | |
| 92 | edges = append(edges, Edge[EdgeType, VertexType]{From: from, To: to, Edge: edgeType}) |
| 93 | } |
| 94 | |
| 95 | return edges |
| 96 | } |
| 97 | |
| 98 | // GetReverseAdjacentVertices returns all the edges that terminate at the given vertex. |
| 99 | func (g *Graph[EdgeType, VertexType]) GetReverseAdjacentVertices(to VertexType) []Edge[EdgeType, VertexType] { |