-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathoid_sorter.go
50 lines (44 loc) · 926 Bytes
/
oid_sorter.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 main
import "github.com/posteo/go-agentx/value"
type OIDSorter []value.OID
func (os OIDSorter) Len() int {
return len(os)
}
func (os OIDSorter) Swap(i, j int) {
os[i], os[j] = os[j], os[i]
}
func (os OIDSorter) Less(i, j int) bool {
return OIDLessThan(os[i], os[j])
}
func OIDLessThan(oid value.OID, other value.OID) bool {
len_left := len(oid)
len_right := len(other)
to := len_left
if len_right < len_left {
to = len_right
}
for k := 0; k < to; k++ {
if oid[k] < other[k] {
return true
} else if oid[k] > other[k] {
return false
}
}
return len_left < len_right
}
func OIDGreaterThan(oid value.OID, other value.OID) bool {
len_left := len(oid)
len_right := len(other)
to := len_left
if len_right < len_left {
to = len_right
}
for k := 0; k < to; k++ {
if oid[k] > other[k] {
return true
} else if oid[k] < other[k] {
return false
}
}
return len_left > len_right
}