| // Copyright 2015 The Vanadium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| // clock is a type for the vector clock, which is used to keep track |
| // of logical time in a concurrent program. |
| // newClock is the clock factory. |
| // clone produces a copy of the clock. |
| func (c clock) clone() clock { |
| // equals checks if this clock identifies a logical time identical to |
| // the logical time identified by the given clock. |
| func (c clock) equals(other clock) bool { |
| return reflect.DeepEqual(c, other) |
| // happensBefore checks if this clock identifies a logical time that |
| // happened before (in the sense of Lamport's happens-before relation) |
| // the logical time identified by the given clock. |
| func (c clock) happensBefore(other clock) bool { |
| if value, found := other[k]; !found || v > value { |
| // merge merges the value of the given clock with this clock. |
| func (c clock) merge(other clock) { |
| for key, value := range other { |
| if v, found := c[key]; !found || v < value { |