aboutsummaryrefslogtreecommitdiff
path: root/chapter/6/resources
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
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')
-rw-r--r--chapter/6/resources/code/counters/python/operation-based-increment-and-decrement-counter.py20
-rw-r--r--chapter/6/resources/code/counters/python/operation-based-increment-only-counter.py15
-rw-r--r--chapter/6/resources/code/counters/python/state-based-increment-and-decrement-counter-correct.py47
-rw-r--r--chapter/6/resources/code/counters/python/state-based-increment-and-decrement-counter-incorrect.py31
-rw-r--r--chapter/6/resources/code/counters/python/state-based-increment-only-counter-correct.py28
-rw-r--r--chapter/6/resources/code/counters/python/state-based-increment-only-counter-incorrect.py19
-rw-r--r--chapter/6/resources/images/counters/decrement-operation.pngbin0 -> 1775 bytes
-rw-r--r--chapter/6/resources/images/counters/increment-and-decrement-operations-commute.pngbin0 -> 22837 bytes
-rw-r--r--chapter/6/resources/images/counters/increment-operation.pngbin0 -> 1649 bytes
-rw-r--r--chapter/6/resources/images/counters/operation-based-increment-and-decrement-counter.pngbin0 -> 231349 bytes
-rw-r--r--chapter/6/resources/images/counters/operation-based-increment-only-counter.pngbin0 -> 275467 bytes
-rw-r--r--chapter/6/resources/images/counters/state-based-increment-and-decrement-counter-correct-lattice.pngbin0 -> 1346630 bytes
-rw-r--r--chapter/6/resources/images/counters/state-based-increment-and-decrement-counter-correct.pngbin0 -> 302107 bytes
-rw-r--r--chapter/6/resources/images/counters/state-based-increment-and-decrement-counter-incorrect-lattice.pngbin0 -> 42949 bytes
-rw-r--r--chapter/6/resources/images/counters/state-based-increment-and-decrement-counter-incorrect.pngbin0 -> 298653 bytes
-rw-r--r--chapter/6/resources/images/counters/state-based-increment-only-counter-correct.pngbin0 -> 282239 bytes
-rw-r--r--chapter/6/resources/images/counters/state-based-increment-only-counter-incorrect.pngbin0 -> 283474 bytes
-rw-r--r--chapter/6/resources/images/partitioned-network.jpg (renamed from chapter/6/resources/partitioned-network.jpg)bin24303 -> 24303 bytes
18 files changed, 160 insertions, 0 deletions
diff --git a/chapter/6/resources/code/counters/python/operation-based-increment-and-decrement-counter.py b/chapter/6/resources/code/counters/python/operation-based-increment-and-decrement-counter.py
new file mode 100644
index 0000000..5182ab1
--- /dev/null
+++ b/chapter/6/resources/code/counters/python/operation-based-increment-and-decrement-counter.py
@@ -0,0 +1,20 @@
+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)
+
+ def decrement(self): # update function
+ self._count -= 1
+ for replica in self.replicas():
+ self.transmit("decrement", replica)
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)
diff --git a/chapter/6/resources/code/counters/python/state-based-increment-and-decrement-counter-correct.py b/chapter/6/resources/code/counters/python/state-based-increment-and-decrement-counter-correct.py
new file mode 100644
index 0000000..1ea726d
--- /dev/null
+++ b/chapter/6/resources/code/counters/python/state-based-increment-and-decrement-counter-correct.py
@@ -0,0 +1,47 @@
+class CvRDT:
+ pass
+
+class Counter(CvRDT):
+
+ def __init__(self,
+ increments = None,
+ decrements = None): # constructor function
+ if increments is None:
+ self._increments = [0] * length(replicas())
+ else:
+ self._increments = increments
+ if decrements is None:
+ self._decrements = [0] * length(replicas())
+ else:
+ self._decrements = decrements
+
+ def increments(self): # query function
+ return list(self._increments) # return a clone
+
+ def decrements(self): # query function
+ return list(self._decrements) # return a clone
+
+ def value(self): # query function
+ return (sum(self.increments()) -
+ sum(self.decrements()))
+
+ def increment(self): # update function
+ self._increments[self.replicaId()] += 1
+
+ def decrement(self): # update function
+ self._decrements[self.replicaId()] += 1
+
+ def compare(self, other): # comparison function
+ return (all(v1 <= v2 for (v1, v2) in
+ zip(self.increments(),
+ other.increments()))
+ and
+ all(v1 <= v2 for (v1, v2) in
+ zip(self.decrements(),
+ other.decrements())))
+
+ def merge(self, other): # merge function
+ return Counter(increments = map(max, zip(self.increments(),
+ other.increments())),
+ decrements = map(max, zip(self.decrements(),
+ other.decrements())))
diff --git a/chapter/6/resources/code/counters/python/state-based-increment-and-decrement-counter-incorrect.py b/chapter/6/resources/code/counters/python/state-based-increment-and-decrement-counter-incorrect.py
new file mode 100644
index 0000000..6f0cbde
--- /dev/null
+++ b/chapter/6/resources/code/counters/python/state-based-increment-and-decrement-counter-incorrect.py
@@ -0,0 +1,31 @@
+class CvRDT:
+ pass
+
+class Counter(CvRDT):
+
+ def __init__(self, counts = None): # constructor function
+ if counts is None:
+ self._counts = [0] * length(self.replicas())
+ else:
+ self._counts = counts
+
+ def value(self): # query function
+ return sum(self._counts)
+
+ def counts(self): # query function
+ return list(self._counts) # return a clone
+
+ def increment(self): # update function
+ self._counts[self.replicaId()] += 1
+
+ def decrement(self): # update function
+ self._counts[self.replicaId()] -= 1
+
+ def compare(self, other): # comparison function
+ return all(v1 <= v2 for (v1, v2) in
+ zip(self.counts(),
+ other.counts()))
+
+ def merge(self, other): # merge function
+ return Counter(map(max, zip(self.counts(),
+ other.counts())))
diff --git a/chapter/6/resources/code/counters/python/state-based-increment-only-counter-correct.py b/chapter/6/resources/code/counters/python/state-based-increment-only-counter-correct.py
new file mode 100644
index 0000000..a3d9069
--- /dev/null
+++ b/chapter/6/resources/code/counters/python/state-based-increment-only-counter-correct.py
@@ -0,0 +1,28 @@
+class CvRDT:
+ pass
+
+class Counter(CvRDT):
+
+ def __init__(self, counts = None): # constructor function
+ if counts is None:
+ self._counts = [0] * length(self.replicas())
+ else:
+ self._counts = counts
+
+ def value(self): # query function
+ return sum(self._counts)
+
+ def counts(self): # query function
+ return list(self._counts) # return a clone
+
+ def increment(self): # update function
+ self._counts[self.replicaId()] += 1
+
+ def compare(self, other): # comparison function
+ return all(v1 <= v2 for (v1, v2) in
+ zip(self.counts(),
+ other.counts()))
+
+ def merge(self, other): # merge function
+ return Counter(map(max, zip(self.counts(),
+ other.counts())))
diff --git a/chapter/6/resources/code/counters/python/state-based-increment-only-counter-incorrect.py b/chapter/6/resources/code/counters/python/state-based-increment-only-counter-incorrect.py
new file mode 100644
index 0000000..9971c65
--- /dev/null
+++ b/chapter/6/resources/code/counters/python/state-based-increment-only-counter-incorrect.py
@@ -0,0 +1,19 @@
+class CvRDT:
+ pass
+
+class Counter(CvRDT):
+
+ def __init__(self, count = 0): # constructor function
+ self._count = count
+
+ def value(self): # query function
+ return self._count
+
+ def increment(self): # update function
+ self._count += 1
+
+ def compare(self, other): # comparison function
+ return self.value() <= other.value()
+
+ def merge(self, other): # merge function
+ return Counter(max(self.value(), other.value()))
diff --git a/chapter/6/resources/images/counters/decrement-operation.png b/chapter/6/resources/images/counters/decrement-operation.png
new file mode 100644
index 0000000..a2d3f1a
--- /dev/null
+++ b/chapter/6/resources/images/counters/decrement-operation.png
Binary files differ
diff --git a/chapter/6/resources/images/counters/increment-and-decrement-operations-commute.png b/chapter/6/resources/images/counters/increment-and-decrement-operations-commute.png
new file mode 100644
index 0000000..93b52bf
--- /dev/null
+++ b/chapter/6/resources/images/counters/increment-and-decrement-operations-commute.png
Binary files differ
diff --git a/chapter/6/resources/images/counters/increment-operation.png b/chapter/6/resources/images/counters/increment-operation.png
new file mode 100644
index 0000000..f016c23
--- /dev/null
+++ b/chapter/6/resources/images/counters/increment-operation.png
Binary files differ
diff --git a/chapter/6/resources/images/counters/operation-based-increment-and-decrement-counter.png b/chapter/6/resources/images/counters/operation-based-increment-and-decrement-counter.png
new file mode 100644
index 0000000..ddbc789
--- /dev/null
+++ b/chapter/6/resources/images/counters/operation-based-increment-and-decrement-counter.png
Binary files differ
diff --git a/chapter/6/resources/images/counters/operation-based-increment-only-counter.png b/chapter/6/resources/images/counters/operation-based-increment-only-counter.png
new file mode 100644
index 0000000..1231b92
--- /dev/null
+++ b/chapter/6/resources/images/counters/operation-based-increment-only-counter.png
Binary files differ
diff --git a/chapter/6/resources/images/counters/state-based-increment-and-decrement-counter-correct-lattice.png b/chapter/6/resources/images/counters/state-based-increment-and-decrement-counter-correct-lattice.png
new file mode 100644
index 0000000..2bbcf6b
--- /dev/null
+++ b/chapter/6/resources/images/counters/state-based-increment-and-decrement-counter-correct-lattice.png
Binary files differ
diff --git a/chapter/6/resources/images/counters/state-based-increment-and-decrement-counter-correct.png b/chapter/6/resources/images/counters/state-based-increment-and-decrement-counter-correct.png
new file mode 100644
index 0000000..880aee0
--- /dev/null
+++ b/chapter/6/resources/images/counters/state-based-increment-and-decrement-counter-correct.png
Binary files differ
diff --git a/chapter/6/resources/images/counters/state-based-increment-and-decrement-counter-incorrect-lattice.png b/chapter/6/resources/images/counters/state-based-increment-and-decrement-counter-incorrect-lattice.png
new file mode 100644
index 0000000..d13dfaa
--- /dev/null
+++ b/chapter/6/resources/images/counters/state-based-increment-and-decrement-counter-incorrect-lattice.png
Binary files differ
diff --git a/chapter/6/resources/images/counters/state-based-increment-and-decrement-counter-incorrect.png b/chapter/6/resources/images/counters/state-based-increment-and-decrement-counter-incorrect.png
new file mode 100644
index 0000000..7981767
--- /dev/null
+++ b/chapter/6/resources/images/counters/state-based-increment-and-decrement-counter-incorrect.png
Binary files differ
diff --git a/chapter/6/resources/images/counters/state-based-increment-only-counter-correct.png b/chapter/6/resources/images/counters/state-based-increment-only-counter-correct.png
new file mode 100644
index 0000000..c382f8b
--- /dev/null
+++ b/chapter/6/resources/images/counters/state-based-increment-only-counter-correct.png
Binary files differ
diff --git a/chapter/6/resources/images/counters/state-based-increment-only-counter-incorrect.png b/chapter/6/resources/images/counters/state-based-increment-only-counter-incorrect.png
new file mode 100644
index 0000000..3e79e42
--- /dev/null
+++ b/chapter/6/resources/images/counters/state-based-increment-only-counter-incorrect.png
Binary files differ
diff --git a/chapter/6/resources/partitioned-network.jpg b/chapter/6/resources/images/partitioned-network.jpg
index 513fc13..513fc13 100644
--- a/chapter/6/resources/partitioned-network.jpg
+++ b/chapter/6/resources/images/partitioned-network.jpg
Binary files differ