forked from openshift/origin
/
util.go
44 lines (33 loc) · 805 Bytes
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// 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 concrete
import (
"math"
"github.com/gonum/graph"
)
type nodeSorter []graph.Node
func (ns nodeSorter) Less(i, j int) bool {
return ns[i].ID() < ns[j].ID()
}
func (ns nodeSorter) Swap(i, j int) {
ns[i], ns[j] = ns[j], ns[i]
}
func (ns nodeSorter) Len() int {
return len(ns)
}
// The math package only provides explicitly sized max
// values. This ensures we get the max for the actual
// type int.
const maxInt int = int(^uint(0) >> 1)
var inf = math.Inf(1)
func isSame(a, b float64) bool {
return a == b || (math.IsNaN(a) && math.IsNaN(b))
}
func max(a, b int) int {
if a > b {
return a
} else {
return b
}
}