| 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 |
| 7 #include <algorithm> |
| 8 |
| 9 #include "base/logging.h" |
| 10 |
| 11 namespace blimp { |
| 12 |
| 13 VectorClock::VectorClock() {} |
| 14 |
| 15 VectorClock::VectorClock(Revision local_revision, Revision 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()); |
| 20 |
| 21 if (local_revision_ == other.local_revision()) { |
| 22 if (remote_revision_ == other.remote_revision()) { |
| 23 return VectorClock::Comparison::EqualTo; |
| 24 } else if (remote_revision_ < other.remote_revision()) { |
| 25 return VectorClock::Comparison::LessThan; |
| 26 } else { |
| 27 return VectorClock::Comparison::GreaterThan; |
| 28 } |
| 29 } else { |
| 30 if (local_revision_ > other.local_revision()) { |
| 31 if (remote_revision_ == other.remote_revision()) { |
| 32 return VectorClock::Comparison::GreaterThan; |
| 33 } else { |
| 34 return VectorClock::Comparison::Conflict; |
| 35 } |
| 36 } else { // We know its not equal or greater, so its smaller |
| 37 if (remote_revision_ == other.remote_revision()) { |
| 38 return VectorClock::Comparison::LessThan; |
| 39 } else { |
| 40 LOG(FATAL) << "Local revision should always be greater or equal."; |
| 41 return VectorClock::Comparison::Conflict; |
| 42 } |
| 43 } |
| 44 } |
| 45 } |
| 46 |
| 47 VectorClock VectorClock::MergeWith(const VectorClock& other) const { |
| 48 VectorClock result(std::max(local_revision_, other.local_revision()), |
| 49 std::max(remote_revision_, other.remote_revision())); |
| 50 return result; |
| 51 } |
| 52 |
| 53 void VectorClock::IncrementLocal() { |
| 54 local_revision_++; |
| 55 } |
| 56 |
| 57 } // namespace blimp |
| OLD | NEW |