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

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

Issue 2372903002: Helium: Adding vector clock (Closed)
Patch Set: allowing merge with conflicted vectors 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
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..78bfa4947325a71520fb18286a8600899ea83061
--- /dev/null
+++ b/blimp/net/helium/vector_clock.cc
@@ -0,0 +1,49 @@
+// 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>
Kevin M 2016/09/27 17:31:09 Add newline before and after <algorithm>
scf 2016/09/27 18:29:59 Done.
+#include "base/logging.h"
+
+namespace blimp {
+
+VectorClock::VectorClock(int32_t local_revision, int32_t remote_revision)
+ : local_revision_(local_revision), remote_revision_(remote_revision) {}
+
+VectorClock::Comparison VectorClock::CompareTo(const VectorClock& other) const {
Kevin M 2016/09/27 17:31:09 Add DCHECK(local_revision_ >= other.local_revision
scf 2016/09/27 18:29:58 Done.
+ 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::Conflicts;
+ }
+ } else {
+ // its smaller <
Kevin M 2016/09/27 17:31:09 Can you rework comment to be a well formed sentenc
scf 2016/09/27 18:29:58 Done.
+ if (remote_revision_ == other.remote_revision_) {
+ return VectorClock::Comparison::LessThan;
+ } else {
+ return VectorClock::Comparison::Conflicts;
+ }
+ }
+ }
+}
+VectorClock VectorClock::MergeWith(const VectorClock& other) {
Kevin M 2016/09/27 17:31:09 add newline above
scf 2016/09/27 18:29:58 Done.
+ VectorClock result(std::max(local_revision_, other.local_revision_),
Kevin M 2016/09/27 17:31:09 Can you use the getter() to access |other|'s membe
scf 2016/09/27 18:29:59 Done.
+ std::max(remote_revision_, other.remote_revision_));
+ return result;
+}
+void VectorClock::IncrementLocal() {
Kevin M 2016/09/27 17:31:09 add newline above
scf 2016/09/27 18:29:58 Done.
+ local_revision_++;
+}
+
+} // namespace blimp

Powered by Google App Engine
This is Rietveld 408576698