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

Side by Side Diff: blimp/helium/version_vector.cc

Issue 2602103002: Delete blimp/helium and remove references to it from dependent targets (Closed)
Patch Set: . Created 3 years, 11 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
« no previous file with comments | « blimp/helium/version_vector.h ('k') | blimp/helium/version_vector_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/helium/version_vector.h"
6
7 #include <algorithm>
8
9 #include "base/logging.h"
10
11 namespace blimp {
12 namespace helium {
13
14 VersionVector::VersionVector() {}
15
16 VersionVector::VersionVector(Revision local_revision, Revision remote_revision)
17 : local_revision_(local_revision), remote_revision_(remote_revision) {}
18
19 VersionVector::Comparison VersionVector::CompareTo(
20 const VersionVector& other) const {
21 DCHECK_GE(local_revision_, other.local_revision());
22
23 if (local_revision_ == other.local_revision()) {
24 if (remote_revision_ == other.remote_revision()) {
25 return VersionVector::Comparison::EqualTo;
26 } else if (remote_revision_ < other.remote_revision()) {
27 return VersionVector::Comparison::LessThan;
28 } else {
29 return VersionVector::Comparison::GreaterThan;
30 }
31 } else {
32 if (local_revision_ > other.local_revision()) {
33 if (remote_revision_ == other.remote_revision()) {
34 return VersionVector::Comparison::GreaterThan;
35 } else {
36 return VersionVector::Comparison::Conflict;
37 }
38 } else { // We know its not equal or greater, so its smaller
39 if (remote_revision_ == other.remote_revision()) {
40 return VersionVector::Comparison::LessThan;
41 } else {
42 LOG(FATAL) << "Local revision should always be greater or equal.";
43 return VersionVector::Comparison::Conflict;
44 }
45 }
46 }
47 }
48
49 VersionVector::Comparison VersionVector::CompareWithBias(
50 const VersionVector& other,
51 Bias bias) const {
52 Comparison cmp = CompareTo(other);
53 if (cmp == Comparison::Conflict) {
54 if (bias == Bias::REMOTE) {
55 return Comparison::LessThan;
56 } else if (bias == Bias::LOCAL) {
57 return Comparison::GreaterThan;
58 }
59 }
60 return cmp;
61 }
62
63 VersionVector VersionVector::MergeWith(const VersionVector& other) const {
64 VersionVector result(std::max(local_revision_, other.local_revision()),
65 std::max(remote_revision_, other.remote_revision()));
66 return result;
67 }
68
69 void VersionVector::IncrementLocal() {
70 local_revision_++;
71 }
72
73 proto::VersionVectorMessage VersionVector::ToProto() const {
74 proto::VersionVectorMessage result;
75 result.set_local_revision(local_revision_);
76 result.set_remote_revision(remote_revision_);
77 return result;
78 }
79
80 VersionVector VersionVector::Invert() const {
81 return VersionVector(remote_revision_, local_revision_);
82 }
83
84 } // namespace helium
85 } // namespace blimp
OLDNEW
« no previous file with comments | « blimp/helium/version_vector.h ('k') | blimp/helium/version_vector_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698