Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(349)

Side by Side Diff: blimp/net/helium/vector_clock.cc

Issue 2372903002: Helium: Adding vector clock (Closed)
Patch Set: Missed one feedback (s/r/Conflicts/Conflict) Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 #include "blimp/net/helium/vector_clock.h"
6
7 #include <algorithm>
8
9 #include "base/logging.h"
10
11 namespace blimp {
12
13 VectorClock::VectorClock() : local_revision_(0), remote_revision_(0) {}
14
15 VectorClock::VectorClock(int32_t local_revision, int32_t remote_revision)
16 : local_revision_(local_revision), remote_revision_(remote_revision) {}
17
18 VectorClock::Comparison VectorClock::CompareTo(const VectorClock& other) const {
19 DCHECK(local_revision() >= other.local_revision());
Kevin M 2016/09/27 21:36:09 add blank line below dchecks
scf 2016/09/27 23:23:10 Done.
20 if (local_revision() == other.local_revision()) {
21 if (remote_revision() == other.remote_revision()) {
22 return VectorClock::Comparison::EqualTo;
23 } else if (remote_revision() < other.remote_revision()) {
24 return VectorClock::Comparison::LessThan;
25 } else {
26 return VectorClock::Comparison::GreaterThan;
27 }
28 } else {
29 if (local_revision() > other.local_revision()) {
30 if (remote_revision() == other.remote_revision()) {
31 return VectorClock::Comparison::GreaterThan;
32 } else {
33 return VectorClock::Comparison::Conflict;
34 }
35 } else { // We know its not equal or greater, so its smaller
36 if (remote_revision() == other.remote_revision()) {
37 return VectorClock::Comparison::LessThan;
38 } else {
39 DCHECK(false) << "Local revision should always be greater or equal.";
Kevin M 2016/09/27 21:36:09 * Already checked in the top of CompareTo. * No ne
scf 2016/09/27 23:23:10 Done.
40 return VectorClock::Comparison::Conflict;
41 }
42 }
43 }
44 }
45
46 VectorClock VectorClock::MergeWith(const VectorClock& other) const {
47 VectorClock result(std::max(local_revision(), other.local_revision()),
48 std::max(remote_revision(), other.remote_revision()));
49 return result;
50 }
51
52 void VectorClock::IncrementLocal() {
53 set_local_revision(local_revision() + 1);
Kevin M 2016/09/27 21:36:09 Accesses to members of |this| needn't be mediated
scf 2016/09/27 23:23:10 Done.
54 }
55
56 } // namespace blimp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698