Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "blimp/net/helium/vector_clock.h" | 5 #include "blimp/net/helium/vector_clock.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 | 10 |
| 11 namespace blimp { | 11 namespace blimp { |
| 12 | 12 |
| 13 VectorClock::VectorClock() {} | 13 VectorClock::VectorClock() {} |
| 14 | 14 |
| 15 VectorClock::VectorClock(Revision local_revision, Revision remote_revision) | 15 VectorClock::VectorClock(Revision local_revision, Revision remote_revision) |
| 16 : local_revision_(local_revision), remote_revision_(remote_revision) {} | 16 : local_revision_(local_revision), remote_revision_(remote_revision) {} |
| 17 | 17 |
| 18 VectorClock::Comparison VectorClock::CompareTo(const VectorClock& other) const { | 18 VectorClock::Comparison VectorClock::CompareTo(const VectorClock& other) const { |
|
Sriram
2016/09/29 18:52:21
Nit: Might be worth adding Unit tests to for the m
| |
| 19 DCHECK(local_revision_ >= other.local_revision()); | 19 DCHECK(local_revision_ >= other.local_revision()); |
|
Sriram
2016/09/29 18:52:21
Can you add comment as to why Comparison() expects
| |
| 20 | 20 |
| 21 if (local_revision_ == other.local_revision()) { | 21 if (local_revision_ == other.local_revision()) { |
| 22 if (remote_revision_ == other.remote_revision()) { | 22 if (remote_revision_ == other.remote_revision()) { |
| 23 return VectorClock::Comparison::EqualTo; | 23 return VectorClock::Comparison::EqualTo; |
| 24 } else if (remote_revision_ < other.remote_revision()) { | 24 } else if (remote_revision_ < other.remote_revision()) { |
| 25 return VectorClock::Comparison::LessThan; | 25 return VectorClock::Comparison::LessThan; |
| 26 } else { | 26 } else { |
| 27 return VectorClock::Comparison::GreaterThan; | 27 return VectorClock::Comparison::GreaterThan; |
| 28 } | 28 } |
| 29 } else { | 29 } else { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 47 VectorClock VectorClock::MergeWith(const VectorClock& other) const { | 47 VectorClock VectorClock::MergeWith(const VectorClock& other) const { |
| 48 VectorClock result(std::max(local_revision_, other.local_revision()), | 48 VectorClock result(std::max(local_revision_, other.local_revision()), |
| 49 std::max(remote_revision_, other.remote_revision())); | 49 std::max(remote_revision_, other.remote_revision())); |
| 50 return result; | 50 return result; |
| 51 } | 51 } |
| 52 | 52 |
| 53 void VectorClock::IncrementLocal() { | 53 void VectorClock::IncrementLocal() { |
| 54 local_revision_++; | 54 local_revision_++; |
| 55 } | 55 } |
| 56 | 56 |
| 57 helium::VectorClock VectorClock::CreateProto() { | |
| 58 helium::VectorClock result; | |
|
CJ
2016/09/29 20:36:55
Is helium::VectorClock the message? Hard to tell.
scf
2016/09/29 23:13:39
I was following the convention of other proto file
CJ
2016/09/29 23:44:00
The file names leave off the "message" part, but t
scf
2016/09/30 17:26:23
HeliumMessage sounds good?
CJ
2016/09/30 19:47:12
Well, this is for a VectorClock message right? So
scf
2016/09/30 22:13:23
talked offline. Suffixing everything to contain Me
| |
| 59 result.set_local_revision(local_revision_); | |
| 60 result.set_remote_revision(remote_revision_); | |
| 61 return result; | |
| 62 } | |
| 63 | |
| 64 VectorClock VectorClock::Invert() { | |
| 65 VectorClock result; | |
| 66 result.set_local_revision(remote_revision_); | |
| 67 result.set_remote_revision(local_revision_); | |
| 68 return result; | |
| 69 } | |
| 70 | |
| 57 } // namespace blimp | 71 } // namespace blimp |
| OLD | NEW |