pgraph: Panic if vertex is nil
These should be caught early.
This commit is contained in:
@@ -208,6 +208,9 @@ func (g *Graph) AddVertex(xv ...Vertex) {
|
|||||||
g.adjacency = make(map[Vertex]map[Vertex]Edge)
|
g.adjacency = make(map[Vertex]map[Vertex]Edge)
|
||||||
}
|
}
|
||||||
for _, v := range xv {
|
for _, v := range xv {
|
||||||
|
if v == nil {
|
||||||
|
panic("nil vertex")
|
||||||
|
}
|
||||||
if _, exists := g.adjacency[v]; !exists {
|
if _, exists := g.adjacency[v]; !exists {
|
||||||
g.adjacency[v] = make(map[Vertex]Edge)
|
g.adjacency[v] = make(map[Vertex]Edge)
|
||||||
}
|
}
|
||||||
@@ -219,6 +222,9 @@ func (g *Graph) AddVertex(xv ...Vertex) {
|
|||||||
func (g *Graph) DeleteVertex(xv ...Vertex) {
|
func (g *Graph) DeleteVertex(xv ...Vertex) {
|
||||||
if len(xv) == 1 {
|
if len(xv) == 1 {
|
||||||
v := xv[0]
|
v := xv[0]
|
||||||
|
if v == nil {
|
||||||
|
panic("nil vertex")
|
||||||
|
}
|
||||||
delete(g.adjacency, v)
|
delete(g.adjacency, v)
|
||||||
for k := range g.adjacency {
|
for k := range g.adjacency {
|
||||||
delete(g.adjacency[k], v)
|
delete(g.adjacency[k], v)
|
||||||
|
|||||||
Reference in New Issue
Block a user