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

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

Issue 2372903002: Helium: Adding vector clock (Closed)
Patch Set: Missed to update one revision 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) {}
Kevin M 2016/09/28 01:23:15 Put the zeroes in the .h as inline initializers
scf 2016/09/28 16:40:37 Done.
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 DLOG(FATAL) << "Local revision should always be greater or equal.";
Kevin M 2016/09/28 01:23:15 This state is pretty messed up, right? Maybe we sh
scf 2016/09/28 16:40:37 Done.
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698