getOrCreateVertexID returns the ID for a vertex, creating it if it doesn't exist.
(vertex VertexType)
| 123 | |
| 124 | // getOrCreateVertexID returns the ID for a vertex, creating it if it doesn't exist. |
| 125 | func (g *Graph[EdgeType, VertexType]) getOrCreateVertexID(vertex VertexType) int64 { |
| 126 | if id, exists := g.vertexToID[vertex]; exists { |
| 127 | return id |
| 128 | } |
| 129 | |
| 130 | id := g.nextID |
| 131 | g.nextID++ |
| 132 | g.vertexToID[vertex] = id |
| 133 | g.idToVertex[id] = vertex |
| 134 | |
| 135 | // Add the node to the gonum graph |
| 136 | g.gonumGraph.AddNode(simple.Node(id)) |
| 137 | |
| 138 | return id |
| 139 | } |
| 140 | |
| 141 | // canReach checks if there is a path from the start vertex to the end vertex. |
| 142 | func (g *Graph[EdgeType, VertexType]) canReach(start, end VertexType) bool { |