code: func (g *Graph) SortNodes(nodes []*Node, orderBy string) error {
  	if err := validateOrder(orderBy); err != nil {
  		return err
  	}
  
  	// Only nodes from the same graph are comparable to each other. Comparing
  	// .Index from different graphs makes no sense.
  	for _, n := range nodes {
  		if !n.BelongsTo(g) {
  			return fmt.Errorf("bad node %s - from another graph", n)
  		}
  	}
  
  	switch orderBy {
  	case "def":
  		sort.Slice(nodes, func(i, j int) bool { return nodes[i].Index < nodes[j].Index })
  	case "key":
  		sort.Slice(nodes, func(i, j int) bool { return nodes[i].Key.Less(nodes[j].Key) })
  	default:
  		// Must not happen, orderBy must already be validated here.
  		panic(fmt.Sprintf("unknown order %q", orderBy))
  	}
  	return nil
  }
docs: // SortNodes sorts a slice of nodes of this graph in-place.
  //
  // The order of the result depends on the value of 'orderBy':
  //   'key': nodes are ordered lexicographically by their keys (smaller first).
  //   'def': nodes are ordered by the order they were defined in the graph.
  //
  // Any other value of 'orderBy' causes an error.