MCPcopy Index your code
hub / github.com/coder/coder / getOrCreateVertexID

Method getOrCreateVertexID

agent/unit/graph.go:125–139  ·  view source on GitHub ↗

getOrCreateVertexID returns the ID for a vertex, creating it if it doesn't exist.

(vertex VertexType)

Source from the content-addressed store, hash-verified

123
124// getOrCreateVertexID returns the ID for a vertex, creating it if it doesn't exist.
125func (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.
142func (g *Graph[EdgeType, VertexType]) canReach(start, end VertexType) bool {

Callers 1

AddEdgeMethod · 0.95

Calls 1

NodeMethod · 0.65

Tested by

no test coverage detected