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

Unified Diff: blimp/net/helium/vector_clock.cc

Issue 2372903002: Helium: Adding vector clock (Closed)
Patch Set: Fixing CQ issue regarding net export Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « blimp/net/helium/vector_clock.h ('k') | blimp/net/helium/vector_clock_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: blimp/net/helium/vector_clock.cc
diff --git a/blimp/net/helium/vector_clock.cc b/blimp/net/helium/vector_clock.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6b13d28745bd93e1ddb8793b4097e0c275709e98
--- /dev/null
+++ b/blimp/net/helium/vector_clock.cc
@@ -0,0 +1,57 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "blimp/net/helium/vector_clock.h"
+
+#include <algorithm>
+
+#include "base/logging.h"
+
+namespace blimp {
+
+VectorClock::VectorClock() {}
+
+VectorClock::VectorClock(Revision local_revision, Revision remote_revision)
+ : local_revision_(local_revision), remote_revision_(remote_revision) {}
+
+VectorClock::Comparison VectorClock::CompareTo(const VectorClock& other) const {
+ DCHECK(local_revision_ >= other.local_revision());
+
+ if (local_revision_ == other.local_revision()) {
+ if (remote_revision_ == other.remote_revision()) {
+ return VectorClock::Comparison::EqualTo;
+ } else if (remote_revision_ < other.remote_revision()) {
+ return VectorClock::Comparison::LessThan;
+ } else {
+ return VectorClock::Comparison::GreaterThan;
+ }
+ } else {
+ if (local_revision_ > other.local_revision()) {
+ if (remote_revision_ == other.remote_revision()) {
+ return VectorClock::Comparison::GreaterThan;
+ } else {
+ return VectorClock::Comparison::Conflict;
+ }
+ } else { // We know its not equal or greater, so its smaller
+ if (remote_revision_ == other.remote_revision()) {
+ return VectorClock::Comparison::LessThan;
+ } else {
+ LOG(FATAL) << "Local revision should always be greater or equal.";
+ return VectorClock::Comparison::Conflict;
+ }
+ }
+ }
+}
+
+VectorClock VectorClock::MergeWith(const VectorClock& other) const {
+ VectorClock result(std::max(local_revision_, other.local_revision()),
+ std::max(remote_revision_, other.remote_revision()));
+ return result;
+}
+
+void VectorClock::IncrementLocal() {
+ local_revision_++;
+}
+
+} // namespace blimp
« no previous file with comments | « blimp/net/helium/vector_clock.h ('k') | blimp/net/helium/vector_clock_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698