-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrapport.go
74 lines (59 loc) · 1.41 KB
/
rapport.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
68
69
70
71
72
73
74
package rapport
import (
"time"
"github.com/luma/pith/rapport/causality"
)
// ProtoVersion is of the form major.minor.patch-label
const ProtoVersion = "1.0.0-alpha.0"
// Marshaler exposes method to Marshal and Unmarshal
type Marshaler interface {
Marshal() (data []*Segment, err error)
Unmarshal(data []*Segment) error
}
// CRDT exposes a CRDT compliant Merge method
type CRDT interface {
Merge(other CRDT)
}
// Value encapsulates Rapport Value
type Value interface {
CRDT
Marshaler
}
// SetOperations encapsulates the common set operations
type SetOperations interface {
Contains(value string) bool
Cardinality() int
Difference(other Set) []string
Union(other Set, replica string) Set
Intersect(other Set, replica string) Set
IsSubsetOf(other Set) bool
IsEmpty() bool
}
type Register interface {
CRDT
Marshaler
Set(value string, t time.Time) error
Get() string
}
// Set is the contract that all Pith sets must abide by
type Set interface {
CRDT
Marshaler
SetOperations
Add(values []string, replica string) int
AddOne(value string, replica string) bool
Remove(values []string) int
RemoveOne(value string) *causality.VersionVector
Values() []string
Each(fn func(string))
}
// Counter is the contract that all Pith counters must abide by
type Counter interface {
CRDT
Marshaler
Incr() int64
IncrBy(amount int64) int64
Decr() (int64, error)
DecrBy(amount int64) (int64, error)
Value() int64
}