-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchain_interface.go
60 lines (49 loc) · 1.68 KB
/
chain_interface.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
51
52
53
54
55
56
57
58
59
60
package glo
import (
"hash/fnv"
)
import "github.com/Workiva/go-datastructures/augmentedtree"
// Implement Interval interface functions for ChainInterval
func (ci ChainInterval) LowAtDimension(dim uint64) int64 {
return ci.start
}
func (ci ChainInterval) HighAtDimension(dim uint64) int64 {
return ci.end
}
func (ci ChainInterval) OverlapsAtDimension(iv augmentedtree.Interval, dim uint64) bool {
if (iv.LowAtDimension(dim) <= ci.start) && (ci.end <= iv.HighAtDimension(dim)) {
// self ================
// other =====================
return true
} else if (ci.start <= iv.LowAtDimension(dim)) && (iv.LowAtDimension(dim) <= ci.end) {
// self ================
// other ===============
return true
} else if (ci.start <= iv.HighAtDimension(dim)) && (iv.HighAtDimension(dim) <= ci.end) {
// self ===============
// other =================
return true
}
return false
}
func (ci ChainInterval) ID() uint64 {
h := fnv.New64a()
h.Write([]byte(ci.String()))
return h.Sum64()
}
// Implement Interval interface functions for ChainLink by taking advantage
// of the implemented functions for ChainInterval
func (link *ChainLink) LowAtDimension(dim uint64) int64 {
return link.reference.LowAtDimension(dim)
}
func (link *ChainLink) HighAtDimension(dim uint64) int64 {
return link.reference.HighAtDimension(dim)
}
func (link *ChainLink) OverlapsAtDimension(iv augmentedtree.Interval, dim uint64) bool {
return link.reference.OverlapsAtDimension(iv, dim)
}
func (link *ChainLink) ID() uint64 {
h := fnv.New64a()
h.Write([]byte(link.String()))
return h.Sum64()
}