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 #include "blimp/net/helium/vector_clock.h" | |
| 6 #include <algorithm> | |
|
Kevin M
2016/09/27 17:31:09
Add newline before and after <algorithm>
scf
2016/09/27 18:29:59
Done.
| |
| 7 #include "base/logging.h" | |
| 8 | |
| 9 namespace blimp { | |
| 10 | |
| 11 VectorClock::VectorClock(int32_t local_revision, int32_t remote_revision) | |
| 12 : local_revision_(local_revision), remote_revision_(remote_revision) {} | |
| 13 | |
| 14 VectorClock::Comparison VectorClock::CompareTo(const VectorClock& other) const { | |
|
Kevin M
2016/09/27 17:31:09
Add DCHECK(local_revision_ >= other.local_revision
scf
2016/09/27 18:29:58
Done.
| |
| 15 if (local_revision_ == other.local_revision_) { | |
| 16 if (remote_revision_ == other.remote_revision_) { | |
| 17 return VectorClock::Comparison::EqualTo; | |
| 18 } else if (remote_revision_ < other.remote_revision_) { | |
| 19 return VectorClock::Comparison::LessThan; | |
| 20 } else { | |
| 21 return VectorClock::Comparison::GreaterThan; | |
| 22 } | |
| 23 } else { | |
| 24 if (local_revision_ > other.local_revision_) { | |
| 25 if (remote_revision_ == other.remote_revision_) { | |
| 26 return VectorClock::Comparison::GreaterThan; | |
| 27 } else { | |
| 28 return VectorClock::Comparison::Conflicts; | |
| 29 } | |
| 30 } else { | |
| 31 // its smaller < | |
|
Kevin M
2016/09/27 17:31:09
Can you rework comment to be a well formed sentenc
scf
2016/09/27 18:29:58
Done.
| |
| 32 if (remote_revision_ == other.remote_revision_) { | |
| 33 return VectorClock::Comparison::LessThan; | |
| 34 } else { | |
| 35 return VectorClock::Comparison::Conflicts; | |
| 36 } | |
| 37 } | |
| 38 } | |
| 39 } | |
| 40 VectorClock VectorClock::MergeWith(const VectorClock& other) { | |
|
Kevin M
2016/09/27 17:31:09
add newline above
scf
2016/09/27 18:29:58
Done.
| |
| 41 VectorClock result(std::max(local_revision_, other.local_revision_), | |
|
Kevin M
2016/09/27 17:31:09
Can you use the getter() to access |other|'s membe
scf
2016/09/27 18:29:59
Done.
| |
| 42 std::max(remote_revision_, other.remote_revision_)); | |
| 43 return result; | |
| 44 } | |
| 45 void VectorClock::IncrementLocal() { | |
|
Kevin M
2016/09/27 17:31:09
add newline above
scf
2016/09/27 18:29:58
Done.
| |
| 46 local_revision_++; | |
| 47 } | |
| 48 | |
| 49 } // namespace blimp | |
| OLD | NEW |