Skip to content

Commit 945be60

Browse files
lint on vclock
1 parent d264d32 commit 945be60

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

govec/vclock/vclock.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,19 @@ const (
2020

2121
type VClock map[string]uint64
2222

23+
//FindTicks returns the clock value for a given id, if a value is not
24+
//found false is returned
2325
func (vc VClock) FindTicks(id string) (uint64, bool) {
2426
ticks, ok := vc[id]
2527
return ticks, ok
2628
}
2729

28-
//returns a new vector clock
30+
//New returns a new vector clock
2931
func New() VClock {
3032
return VClock{}
3133
}
3234

35+
//Copy returs a copy of the clock
3336
func (vc VClock) Copy() VClock {
3437
cp := make(map[string]uint64, len(vc))
3538
for key, value := range vc {
@@ -38,14 +41,17 @@ func (vc VClock) Copy() VClock {
3841
return cp
3942
}
4043

44+
//CopyFromMap copys a map to a vector clock
4145
func (vc VClock) CopyFromMap(otherMap map[string]uint64) VClock {
4246
return otherMap
4347
}
4448

49+
//GetMap returns the map typed vector clock
4550
func (vc VClock) GetMap() map[string]uint64 {
4651
return map[string]uint64(vc)
4752
}
4853

54+
//Set assigns a clock value to a clock index
4955
func (vc VClock) Set(id string, ticks uint64) {
5056
vc[id] = ticks
5157
}
@@ -55,6 +61,7 @@ func (vc VClock) Tick(id string) {
5561
vc[id] = vc[id] + 1
5662
}
5763

64+
//LastUpdate returns the clock value of the oldest clock
5865
func (vc VClock) LastUpdate() (last uint64) {
5966
for key := range vc {
6067
if vc[key] > last {
@@ -64,6 +71,8 @@ func (vc VClock) LastUpdate() (last uint64) {
6471
return last
6572
}
6673

74+
//Merge takes the max of all clock values in other and updates the
75+
//values of the callee
6776
func (vc VClock) Merge(other VClock) {
6877
for id := range other {
6978
if vc[id] < other[id] {
@@ -72,6 +81,7 @@ func (vc VClock) Merge(other VClock) {
7281
}
7382
}
7483

84+
//Bytes returns an encoded vector clock
7585
func (vc VClock) Bytes() []byte {
7686
b := new(bytes.Buffer)
7787
enc := gob.NewEncoder(b)
@@ -82,6 +92,7 @@ func (vc VClock) Bytes() []byte {
8292
return b.Bytes()
8393
}
8494

95+
//FromBytes decodes a vector clock
8596
func FromBytes(data []byte) (vc VClock, err error) {
8697
b := new(bytes.Buffer)
8798
b.Write(data)
@@ -91,10 +102,12 @@ func FromBytes(data []byte) (vc VClock, err error) {
91102
return clock, err
92103
}
93104

105+
//PrintVC prints the callees vector clock to stdout
94106
func (vc VClock) PrintVC() {
95107
fmt.Println(vc.ReturnVCString())
96108
}
97109

110+
//ReturnVCString returns a string encoding of a vector clock
98111
func (vc VClock) ReturnVCString() string {
99112
//sort
100113
ids := make([]string, len(vc))
@@ -116,6 +129,8 @@ func (vc VClock) ReturnVCString() string {
116129
return buffer.String()
117130
}
118131

132+
//Compare takes another clock and determines if it is Equal, an
133+
//Ancestor, Decendent, or Concurrent with the callees clock.
119134
func (vc VClock) Compare(other VClock, cond Condition) bool {
120135
var otherIs Condition
121136
// Preliminary qualification based on length

0 commit comments

Comments
 (0)