(id ShortID, now uint64)
| 125 | } |
| 126 | |
| 127 | func (v Vector) updateWithNow(id ShortID, now uint64) Vector { |
| 128 | for i := range v.Counters { |
| 129 | if v.Counters[i].ID == id { |
| 130 | // Update an existing index |
| 131 | v.Counters[i].Value = max(v.Counters[i].Value+1, now) |
| 132 | return v |
| 133 | } else if v.Counters[i].ID > id { |
| 134 | // Insert a new index |
| 135 | nv := make([]Counter, len(v.Counters)+1) |
| 136 | copy(nv, v.Counters[:i]) |
| 137 | nv[i].ID = id |
| 138 | nv[i].Value = max(1, now) |
| 139 | copy(nv[i+1:], v.Counters[i:]) |
| 140 | return Vector{Counters: nv} |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | // Append a new index |
| 145 | return Vector{Counters: append(v.Counters, Counter{ |
| 146 | ID: id, |
| 147 | Value: max(1, now), |
| 148 | })} |
| 149 | } |
| 150 | |
| 151 | // Merge returns the vector containing the maximum indexes from v and b. If it |
| 152 | // is possible, the vector v is updated and returned. If it is not, a copy |
no outgoing calls