forked from tpjg/goriakpbc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rdtset.go
60 lines (52 loc) · 967 Bytes
/
rdtset.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 riak
import (
"bytes"
"github.com/tpjg/goriakpbc/pb"
)
type RDtSet struct {
RDataTypeObject
Value [][]byte
ToAdd [][]byte
ToRemove [][]byte
}
func (set *RDtSet) GetValue() [][]byte {
if set.Value == nil {
return [][]byte{}
}
return set.Value
}
func (set *RDtSet) Add(value []byte) {
for _, e := range set.ToAdd {
if bytes.Compare(e, value) == 0 {
return
}
}
set.ToAdd = append(set.ToAdd, value)
}
func (set *RDtSet) Remove(value []byte) {
for _, e := range set.ToRemove {
if bytes.Compare(e, value) == 0 {
return
}
}
set.ToRemove = append(set.ToRemove, value)
}
func (set *RDtSet) ToOp() *pb.DtOp {
if len(set.ToAdd) == 0 && len(set.ToRemove) == 0 {
return nil
}
return &pb.DtOp{
SetOp: &pb.SetOp{
Adds: set.ToAdd,
Removes: set.ToRemove,
},
}
}
func (set *RDtSet) Store() (err error) {
op := set.ToOp()
if op == nil {
// nothing to do
return nil
}
return set.RDataTypeObject.store(op)
}