Keine Beschreibung

graph.go 909B

1234567891011121314151617181920212223242526272829303132
  1. package main
  2. // GRAPH OMIT
  3. // NodeConstraint is the type constraint for graph nodes:
  4. // they must have an Edges method that returns the Edge's
  5. // that connect to this Node.
  6. type NodeConstraint[Edge any] interface {
  7. Edges() []Edge
  8. }
  9. // EdgeConstraint is the type constraint for graph edges:
  10. // they must have a Nodes method that returns the two Nodes
  11. // that this edge connects.
  12. type EdgeConstraint[Node any] interface {
  13. Nodes() (from, to Node)
  14. }
  15. // Graph is a graph composed of nodes and edges.
  16. type Graph[Node NodeConstraint[Edge], Edge EdgeConstraint[Node]] struct { ... }
  17. // New returns a new graph given a list of nodes.
  18. func New[Node NodeConstraint[Edge], Edge EdgeConstraint[Node]] (nodes []Node) *Graph[Node, Edge] {
  19. ...
  20. }
  21. // ShortestPath returns the shortest path between two nodes,
  22. // as a list of edges.
  23. func (g *Graph[Node, Edge]) ShortestPath(from, to Node) []Edge { ... }
  24. // GRAPH OMIT