Chromium Code Reviews| Index: blimp/net/helium/vector_clock.h |
| diff --git a/blimp/net/helium/vector_clock.h b/blimp/net/helium/vector_clock.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8d13324780a9ae1cca73680961298fb765ef1ba3 |
| --- /dev/null |
| +++ b/blimp/net/helium/vector_clock.h |
| @@ -0,0 +1,63 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef BLIMP_NET_HELIUM_VECTOR_CLOCK_H_ |
| +#define BLIMP_NET_HELIUM_VECTOR_CLOCK_H_ |
| + |
| +#include <stdint.h> |
| + |
| +#include "blimp/net/blimp_net_export.h" |
| + |
| +namespace blimp { |
| + |
| +// From wikipedia: |
|
Kevin M
2016/09/28 01:23:15
I meant, can we summarize what this does for Blimp
scf
2016/09/28 16:40:37
Done.
|
| +// A vector clock is an algorithm for generating a partial ordering of events |
| +// in a distributed system and detecting causality violations. |
| +// |
| +// For more info see: |
| +// https://en.wikipedia.org/wiki/Vector_clock |
| + |
| +typedef int32_t Revision; |
|
Kevin M
2016/09/28 01:23:15
uint32_t?
scf
2016/09/28 16:40:37
Done.
|
| + |
| +class BLIMP_NET_EXPORT VectorClock { |
| + public: |
| + enum class Comparison { LessThan, EqualTo, GreaterThan, Conflict }; |
| + |
| + VectorClock(Revision local_revision, Revision remote_revision); |
| + VectorClock(); |
| + |
| + // Compares two vector clocks. There are 4 possibilities for the result: |
| + // * LessThan: One revision is equal and for the other is smaller. |
| + // (1,0).CompareTo((2, 0)); |
| + // * EqualTo: Both revisions are the same. |
| + // * GreaterThan: One revision is equal and for the other is greater. |
| + // (2,0).CompareTo((1, 0)); |
| + // * Conflict: Both revisions are different. (1,0).CompareTo(0,1) |
| + Comparison CompareTo(const VectorClock& other) const; |
| + |
| + // Merges two vector clocks, this function should be used at synchronization |
|
Kevin M
2016/09/28 01:23:15
Merges two vector clocks. (period) This...
|
| + // points. i.e. when client receives data from the server or vice versa. |
| + VectorClock MergeWith(const VectorClock& other) const; |
| + |
| + // Increments local_revision_ by one. This is used when something changes |
| + // in the local state like setting a property or applying a change set. |
| + void IncrementLocal(); |
| + |
| + Revision local_revision() const { return local_revision_; } |
| + void set_local_revision(Revision local_revision) { |
| + local_revision_ = local_revision; |
| + } |
|
Kevin M
2016/09/28 01:23:15
Add newline after the local_ methods; or separate
|
| + Revision remote_revision() const { return remote_revision_; } |
| + void set_remote_revision(Revision remote_revision) { |
| + remote_revision_ = remote_revision; |
| + } |
| + |
| + private: |
| + Revision local_revision_; |
| + Revision remote_revision_; |
| +}; |
| + |
| +} // namespace blimp |
| + |
| +#endif // BLIMP_NET_HELIUM_VECTOR_CLOCK_H_ |