Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef BLIMP_NET_HELIUM_VECTOR_CLOCK_H_ | |
| 6 #define BLIMP_NET_HELIUM_VECTOR_CLOCK_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 | |
| 10 #include "blimp/net/blimp_net_export.h" | |
| 11 | |
| 12 namespace blimp { | |
| 13 | |
| 14 // 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.
| |
| 15 // A vector clock is an algorithm for generating a partial ordering of events | |
| 16 // in a distributed system and detecting causality violations. | |
| 17 // | |
| 18 // For more info see: | |
| 19 // https://en.wikipedia.org/wiki/Vector_clock | |
| 20 | |
| 21 typedef int32_t Revision; | |
|
Kevin M
2016/09/28 01:23:15
uint32_t?
scf
2016/09/28 16:40:37
Done.
| |
| 22 | |
| 23 class BLIMP_NET_EXPORT VectorClock { | |
| 24 public: | |
| 25 enum class Comparison { LessThan, EqualTo, GreaterThan, Conflict }; | |
| 26 | |
| 27 VectorClock(Revision local_revision, Revision remote_revision); | |
| 28 VectorClock(); | |
| 29 | |
| 30 // Compares two vector clocks. There are 4 possibilities for the result: | |
| 31 // * LessThan: One revision is equal and for the other is smaller. | |
| 32 // (1,0).CompareTo((2, 0)); | |
| 33 // * EqualTo: Both revisions are the same. | |
| 34 // * GreaterThan: One revision is equal and for the other is greater. | |
| 35 // (2,0).CompareTo((1, 0)); | |
| 36 // * Conflict: Both revisions are different. (1,0).CompareTo(0,1) | |
| 37 Comparison CompareTo(const VectorClock& other) const; | |
| 38 | |
| 39 // 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...
| |
| 40 // points. i.e. when client receives data from the server or vice versa. | |
| 41 VectorClock MergeWith(const VectorClock& other) const; | |
| 42 | |
| 43 // Increments local_revision_ by one. This is used when something changes | |
| 44 // in the local state like setting a property or applying a change set. | |
| 45 void IncrementLocal(); | |
| 46 | |
| 47 Revision local_revision() const { return local_revision_; } | |
| 48 void set_local_revision(Revision local_revision) { | |
| 49 local_revision_ = local_revision; | |
| 50 } | |
|
Kevin M
2016/09/28 01:23:15
Add newline after the local_ methods; or separate
| |
| 51 Revision remote_revision() const { return remote_revision_; } | |
| 52 void set_remote_revision(Revision remote_revision) { | |
| 53 remote_revision_ = remote_revision; | |
| 54 } | |
| 55 | |
| 56 private: | |
| 57 Revision local_revision_; | |
| 58 Revision remote_revision_; | |
| 59 }; | |
| 60 | |
| 61 } // namespace blimp | |
| 62 | |
| 63 #endif // BLIMP_NET_HELIUM_VECTOR_CLOCK_H_ | |
| OLD | NEW |