January 2020
Intermediate to advanced
640 pages
16h 56m
English
As we mentioned previously, vertices communicate with each other by exchanging messages. Sending the same message to all immediate neighbors of a particular vertex is an often recurring pattern in several graph algorithms. Let's define a convenience method for handling this fairly common use case:
func (g *Graph) BroadcastToNeighbors(v *Vertex, msg message.Message) error { for _, e := range v.edges { if err := g.SendMessage(e.dstID, msg); err != nil { return err } } return nil }
BroadcastToNeighbors simply iterates the list of edges for a particular vertex and attempts to send the message to each neighbor with the help of the SendMessage method. With the help of SendMessage, compute functions can send a message ...