MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / ValidateColorsOfVertex

Method ValidateColorsOfVertex

graph/coloring/graph.go:44–57  ·  view source on GitHub ↗
(colors map[int]Color)

Source from the content-addressed store, hash-verified

42}
43
44func (g *Graph) ValidateColorsOfVertex(colors map[int]Color) error {
45 if g.vertices != len(colors) {
46 return errors.New("coloring: not all vertices of graph are colored")
47 }
48 // check colors
49 for vertex, neighbours := range g.edges {
50 for nb := range neighbours {
51 if colors[vertex] == colors[nb] {
52 return errors.New("coloring: same colors of neighbouring vertex")
53 }
54 }
55 }
56 return nil
57}

Calls

no outgoing calls