-
Notifications
You must be signed in to change notification settings - Fork 0
/
resp.go
50 lines (43 loc) · 873 Bytes
/
resp.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
45
46
47
48
49
50
package rrs
import "fmt"
// Response represents the optimized result
type Response struct {
Sample
Result []int
// the extra values of rrs process
Val interface{}
}
type responses []Response
func less(this []int, that []int) bool {
for i := 0; i < len(this) && i < len(that); i++ {
if this[i] < that[i] {
return true
} else if this[i] > that[i] {
return false
}
}
if len(this) < len(that) {
return true
} else if len(this) > len(that) {
return false
}
return true
}
func (resp Response) String() string {
s := resp.Sample.String()
return fmt.Sprintf("%v %v", s, resp.Result)
}
// getBest return the the smallest result
func (resps responses) getBest() Response {
var best Response
for i := range resps {
if i == 0 {
best = resps[i]
continue
}
if less(resps[i].Result, best.Result) {
best = resps[i]
}
}
return best
}