-
Notifications
You must be signed in to change notification settings - Fork 1
/
merge.go
46 lines (40 loc) · 865 Bytes
/
merge.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
package chotki
import (
"io"
"slices"
"github.com/drpcorg/chotki/rdx"
)
type Merger interface {
// merges values, sorted old to new
Merge(inputs [][]byte) []byte
}
type PebbleMergeAdaptor struct {
id rdx.ID
rdt byte
old bool
vals [][]byte
}
func (a *PebbleMergeAdaptor) MergeNewer(value []byte) error {
target := make([]byte, len(value))
copy(target, value)
a.vals = append(a.vals, target)
return nil
}
func (a *PebbleMergeAdaptor) MergeOlder(value []byte) error {
target := make([]byte, len(value))
copy(target, value)
a.vals = append(a.vals, target)
a.old = true
return nil
}
func (a *PebbleMergeAdaptor) Finish(includesBase bool) (res []byte, cl io.Closer, err error) {
if a.old {
slices.Reverse(a.vals)
}
inputs := a.vals
if len(inputs) == 0 {
return nil, nil, nil
}
res = rdx.Xmerge(a.rdt, inputs)
return res, nil, nil
}