blob: 4179a07c6ea8f042054f376855951ac77a613310 [file] [log] [blame]
// Copyright ©2014 The Gonum Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package simple
import (
"math"
"gonum.org/v1/gonum/graph"
)
// Node is a simple graph node.
type Node int64
// ID returns the ID number of the node.
func (n Node) ID() int64 {
return int64(n)
}
func newSimpleNode(id int) graph.Node {
return Node(id)
}
// Edge is a simple graph edge.
type Edge struct {
F, T graph.Node
}
// From returns the from-node of the edge.
func (e Edge) From() graph.Node { return e.F }
// To returns the to-node of the edge.
func (e Edge) To() graph.Node { return e.T }
// WeightedEdge is a simple weighted graph edge.
type WeightedEdge struct {
F, T graph.Node
W float64
}
// From returns the from-node of the edge.
func (e WeightedEdge) From() graph.Node { return e.F }
// To returns the to-node of the edge.
func (e WeightedEdge) To() graph.Node { return e.T }
// Weight returns the weight of the edge.
func (e WeightedEdge) Weight() float64 { return e.W }
// isSame returns whether two float64 values are the same where NaN values
// are equalable.
func isSame(a, b float64) bool {
return a == b || (math.IsNaN(a) && math.IsNaN(b))
}
type edgeSetter interface {
SetEdge(e graph.Edge)
}
type weightedEdgeSetter interface {
SetWeightedEdge(e graph.WeightedEdge)
}