AddEdge adds an edge to the graph.
(e *Edge)
| 49 | |
| 50 | // AddEdge adds an edge to the graph. |
| 51 | func (g *Graph) AddEdge(e *Edge) error { |
| 52 | // Verify that the edge has source and destination |
| 53 | if e.Source == nil || e.Destination == nil { |
| 54 | return fmt.Errorf("Both source and destination nodes should be defined") |
| 55 | } |
| 56 | |
| 57 | // Verify that the edge's nodes have been previously added to the graph |
| 58 | if _, ok := g.Nodes[e.Source.Alias]; !ok { |
| 59 | return fmt.Errorf("Source node neeeds to be added to the graph first") |
| 60 | } |
| 61 | if _, ok := g.Nodes[e.Destination.Alias]; !ok { |
| 62 | return fmt.Errorf("Destination node neeeds to be added to the graph first") |
| 63 | } |
| 64 | |
| 65 | e.graph = g |
| 66 | g.Edges = append(g.Edges, e) |
| 67 | return nil |
| 68 | } |
| 69 | |
| 70 | // ExecutionPlan gets the execution plan for given query. |
| 71 | func (g *Graph) ExecutionPlan(q string) (string, error) { |
no outgoing calls