simple.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright ©2014 The gonum Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // Package simple provides a suite of simple graph implementations satisfying
  5. // the gonum/graph interfaces.
  6. package simple
  7. import (
  8. "math"
  9. "k8s.io/kubernetes/third_party/forked/gonum/graph"
  10. )
  11. // Node is a simple graph node.
  12. type Node int
  13. // ID returns the ID number of the node.
  14. func (n Node) ID() int {
  15. return int(n)
  16. }
  17. // Edge is a simple graph edge.
  18. type Edge struct {
  19. F, T graph.Node
  20. W float64
  21. }
  22. // From returns the from-node of the edge.
  23. func (e Edge) From() graph.Node { return e.F }
  24. // To returns the to-node of the edge.
  25. func (e Edge) To() graph.Node { return e.T }
  26. // Weight returns the weight of the edge.
  27. func (e Edge) Weight() float64 { return e.W }
  28. // maxInt is the maximum value of the machine-dependent int type.
  29. const maxInt int = int(^uint(0) >> 1)
  30. // isSame returns whether two float64 values are the same where NaN values
  31. // are equalable.
  32. func isSame(a, b float64) bool {
  33. return a == b || (math.IsNaN(a) && math.IsNaN(b))
  34. }