aboutsummaryrefslogtreecommitdiff
path: root/chapter/6/resources/code/counters/python/operation-based-increment-only-counter.py
diff options
context:
space:
mode:
authorHeather Miller <heather.miller@epfl.ch>2017-01-02 16:10:10 +0100
committerGitHub <noreply@github.com>2017-01-02 16:10:10 +0100
commit8428c40f79060169e85bdf740a9432b933a47160 (patch)
tree9950fdb91b93a3c37c4de8e03d4e853493b59deb /chapter/6/resources/code/counters/python/operation-based-increment-only-counter.py
parent67118db13c3acb378da9a853d8119e82e20d306a (diff)
parentf27ba2bd06be195a06fe11b571aebd9a7c1ef930 (diff)
Merge pull request #17 from aviralg/master
Added images for counter example, need to work on text
Diffstat (limited to 'chapter/6/resources/code/counters/python/operation-based-increment-only-counter.py')
-rw-r--r--chapter/6/resources/code/counters/python/operation-based-increment-only-counter.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/chapter/6/resources/code/counters/python/operation-based-increment-only-counter.py b/chapter/6/resources/code/counters/python/operation-based-increment-only-counter.py
new file mode 100644
index 0000000..b10cd98
--- /dev/null
+++ b/chapter/6/resources/code/counters/python/operation-based-increment-only-counter.py
@@ -0,0 +1,15 @@
+class CmRDT:
+ pass
+
+class Counter(CmRDT):
+
+ def __init__(self): # constructor function
+ self._count = 0
+
+ def value(self): # query function
+ return self._count
+
+ def increment(self): # update function
+ self._count += 1
+ for replica in self.replicas():
+ self.transmit("increment", replica)