-
Notifications
You must be signed in to change notification settings - Fork 0
/
splotchKeys.go
67 lines (59 loc) · 1.42 KB
/
splotchKeys.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
61
62
63
64
65
66
67
package inkdb
import "encoding/binary"
type SplotchKey [8]byte //a 64 bit index string
// lets say the keys are represented in big endian order.
// returns a<b
func (a SplotchKey) LessThan(b SplotchKey) bool {
for i := 0; i < len(a); i++ {
if a[i] == b[i] {
continue
}
return a[i] < b[i]
}
return false
}
// returns a<=b
func (a SplotchKey) LessOrEqual(b SplotchKey) bool {
for i := 0; i < len(a); i++ {
if a[i] == b[i] {
continue
}
return a[i] < b[i]
}
return true
}
func (a SplotchKey) GreaterThan(b SplotchKey) bool {
for i := 0; i < len(a); i++ {
if a[i] == b[i] {
continue
}
return a[i] > b[i]
}
return false
}
func (a SplotchKey) GreaterOrEqual(b SplotchKey) bool {
for i := 0; i < len(a); i++ {
if a[i] == b[i] {
continue
}
return a[i] > b[i]
}
return true
}
func (a SplotchKey) Equal(b SplotchKey) bool {
for i := range a {
if a[i] != b[i] {
return false
}
}
return true
}
// generates the next incremental key
func (k SplotchKey) NextKey() SplotchKey {
return k.Plus(1)
}
// TODO: if i change Splotchkey back to variable length, i need to change this
func (k SplotchKey) Plus(a int) SplotchKey {
//tbh, I'm not entirely sure why I wrote the keys as byte arrays instead of uint64s... Originally i was going to make them more flexible, in length, but decided to change that...
return SplotchKey(binary.BigEndian.AppendUint64([]byte{}, binary.BigEndian.Uint64(k[:])+uint64(a)))
}