-
Notifications
You must be signed in to change notification settings - Fork 2
/
deferred.go
48 lines (36 loc) · 933 Bytes
/
deferred.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
package rapport
import "github.com/luma/pith/rapport/causality"
func MakeDeferredSet() *DeferredSet {
return &DeferredSet{
Members: make(map[string]bool),
}
}
func UnmarshalDeferredSet(data []byte) (*DeferredSet, error) {
set := MakeDeferredSet()
if err := set.Unmarshal(data); err != nil {
return nil, err
}
return set, nil
}
func (d *DeferredSet) Clone() *DeferredSet {
deferred := MakeDeferredSet()
for value := range d.Members {
deferred.Members[value] = true
}
return deferred
}
func (d *DeferredSet) Values() []string {
values := make([]string, 0, len(d.Members))
for value := range d.Members {
values = append(values, value)
}
return values
}
type DeferredMap map[*causality.VersionVector]*DeferredSet
func (d *DeferredMap) Clone() *DeferredMap {
deferredMap := make(DeferredMap)
for version, oldDeferred := range *d {
deferredMap[version] = oldDeferred.Clone()
}
return &deferredMap
}