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

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

Issue 2372903002: Helium: Adding vector clock (Closed)
Patch Set: Missed to update one revision 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.h
diff --git a/blimp/net/helium/vector_clock.h b/blimp/net/helium/vector_clock.h
new file mode 100644
index 0000000000000000000000000000000000000000..8d13324780a9ae1cca73680961298fb765ef1ba3
--- /dev/null
+++ b/blimp/net/helium/vector_clock.h
@@ -0,0 +1,63 @@
+// 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.
+
+#ifndef BLIMP_NET_HELIUM_VECTOR_CLOCK_H_
+#define BLIMP_NET_HELIUM_VECTOR_CLOCK_H_
+
+#include <stdint.h>
+
+#include "blimp/net/blimp_net_export.h"
+
+namespace blimp {
+
+// From wikipedia:
Kevin M 2016/09/28 01:23:15 I meant, can we summarize what this does for Blimp
scf 2016/09/28 16:40:37 Done.
+// A vector clock is an algorithm for generating a partial ordering of events
+// in a distributed system and detecting causality violations.
+//
+// For more info see:
+// https://en.wikipedia.org/wiki/Vector_clock
+
+typedef int32_t Revision;
Kevin M 2016/09/28 01:23:15 uint32_t?
scf 2016/09/28 16:40:37 Done.
+
+class BLIMP_NET_EXPORT VectorClock {
+ public:
+ enum class Comparison { LessThan, EqualTo, GreaterThan, Conflict };
+
+ VectorClock(Revision local_revision, Revision remote_revision);
+ VectorClock();
+
+ // Compares two vector clocks. There are 4 possibilities for the result:
+ // * LessThan: One revision is equal and for the other is smaller.
+ // (1,0).CompareTo((2, 0));
+ // * EqualTo: Both revisions are the same.
+ // * GreaterThan: One revision is equal and for the other is greater.
+ // (2,0).CompareTo((1, 0));
+ // * Conflict: Both revisions are different. (1,0).CompareTo(0,1)
+ Comparison CompareTo(const VectorClock& other) const;
+
+ // Merges two vector clocks, this function should be used at synchronization
Kevin M 2016/09/28 01:23:15 Merges two vector clocks. (period) This...
+ // points. i.e. when client receives data from the server or vice versa.
+ VectorClock MergeWith(const VectorClock& other) const;
+
+ // Increments local_revision_ by one. This is used when something changes
+ // in the local state like setting a property or applying a change set.
+ void IncrementLocal();
+
+ Revision local_revision() const { return local_revision_; }
+ void set_local_revision(Revision local_revision) {
+ local_revision_ = local_revision;
+ }
Kevin M 2016/09/28 01:23:15 Add newline after the local_ methods; or separate
+ Revision remote_revision() const { return remote_revision_; }
+ void set_remote_revision(Revision remote_revision) {
+ remote_revision_ = remote_revision;
+ }
+
+ private:
+ Revision local_revision_;
+ Revision remote_revision_;
+};
+
+} // namespace blimp
+
+#endif // BLIMP_NET_HELIUM_VECTOR_CLOCK_H_

Powered by Google App Engine
This is Rietveld 408576698