From 8956b27b29637a452d0603658f9646b324d904ed Mon Sep 17 00:00:00 2001 From: Aviral Goel Date: Sat, 17 Dec 2016 16:31:29 -0500 Subject: Added specification of counters, moved images to resources --- ...ration-based-increment-and-decrement-counter.py | 20 +++++++++ .../operation-based-increment-only-counter.py | 15 +++++++ ...ased-increment-and-decrement-counter-correct.py | 47 +++++++++++++++++++++ ...ed-increment-and-decrement-counter-incorrect.py | 31 ++++++++++++++ .../state-based-increment-only-counter-correct.py | 28 ++++++++++++ ...state-based-increment-only-counter-incorrect.py | 19 +++++++++ ...ation-based-increment-and-decrement-counter.png | Bin 0 -> 259325 bytes .../operation-based-increment-only-counter.png | Bin 0 -> 236423 bytes ...sed-increment-and-decrement-counter-correct.png | Bin 0 -> 250168 bytes ...d-increment-and-decrement-counter-incorrect.png | Bin 0 -> 247402 bytes .../state-based-increment-only-counter-correct.png | Bin 0 -> 240649 bytes ...tate-based-increment-only-counter-incorrect.png | Bin 0 -> 241905 bytes chapter/6/resources/images/partitioned-network.jpg | Bin 0 -> 24303 bytes chapter/6/resources/partitioned-network.jpg | Bin 24303 -> 0 bytes 14 files changed, 160 insertions(+) create mode 100644 chapter/6/resources/code/counters/python/operation-based-increment-and-decrement-counter.py create mode 100644 chapter/6/resources/code/counters/python/operation-based-increment-only-counter.py create mode 100644 chapter/6/resources/code/counters/python/state-based-increment-and-decrement-counter-correct.py create mode 100644 chapter/6/resources/code/counters/python/state-based-increment-and-decrement-counter-incorrect.py create mode 100644 chapter/6/resources/code/counters/python/state-based-increment-only-counter-correct.py create mode 100644 chapter/6/resources/code/counters/python/state-based-increment-only-counter-incorrect.py create mode 100644 chapter/6/resources/images/counters/operation-based-increment-and-decrement-counter.png create mode 100644 chapter/6/resources/images/counters/operation-based-increment-only-counter.png create mode 100644 chapter/6/resources/images/counters/state-based-increment-and-decrement-counter-correct.png create mode 100644 chapter/6/resources/images/counters/state-based-increment-and-decrement-counter-incorrect.png create mode 100644 chapter/6/resources/images/counters/state-based-increment-only-counter-correct.png create mode 100644 chapter/6/resources/images/counters/state-based-increment-only-counter-incorrect.png create mode 100644 chapter/6/resources/images/partitioned-network.jpg delete mode 100644 chapter/6/resources/partitioned-network.jpg (limited to 'chapter/6/resources') 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/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..f046c0b Binary files /dev/null and b/chapter/6/resources/images/counters/operation-based-increment-and-decrement-counter.png 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..398c562 Binary files /dev/null and b/chapter/6/resources/images/counters/operation-based-increment-only-counter.png 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..0d6468b Binary files /dev/null and b/chapter/6/resources/images/counters/state-based-increment-and-decrement-counter-correct.png 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..3f7f1b9 Binary files /dev/null and b/chapter/6/resources/images/counters/state-based-increment-and-decrement-counter-incorrect.png 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..4ca2843 Binary files /dev/null and b/chapter/6/resources/images/counters/state-based-increment-only-counter-correct.png 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..3f95e59 Binary files /dev/null and b/chapter/6/resources/images/counters/state-based-increment-only-counter-incorrect.png differ diff --git a/chapter/6/resources/images/partitioned-network.jpg b/chapter/6/resources/images/partitioned-network.jpg new file mode 100644 index 0000000..513fc13 Binary files /dev/null and b/chapter/6/resources/images/partitioned-network.jpg differ diff --git a/chapter/6/resources/partitioned-network.jpg b/chapter/6/resources/partitioned-network.jpg deleted file mode 100644 index 513fc13..0000000 Binary files a/chapter/6/resources/partitioned-network.jpg and /dev/null differ -- cgit v1.2.3 From 71d608e799f4f5674c8961e304719743d26066fc Mon Sep 17 00:00:00 2001 From: Aviral Goel Date: Sun, 18 Dec 2016 01:35:23 -0500 Subject: Wrote up description for PN Counter --- .../6/resources/images/counters/decrement-operation.png | Bin 0 -> 1775 bytes .../6/resources/images/counters/increment-operation.png | Bin 0 -> 1649 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 chapter/6/resources/images/counters/decrement-operation.png create mode 100644 chapter/6/resources/images/counters/increment-operation.png (limited to 'chapter/6/resources') 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 Binary files /dev/null and b/chapter/6/resources/images/counters/decrement-operation.png 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 Binary files /dev/null and b/chapter/6/resources/images/counters/increment-operation.png differ -- cgit v1.2.3 From 4265d72a46759e930436bf0c6349982ecf0adabd Mon Sep 17 00:00:00 2001 From: Aviral Goel Date: Mon, 19 Dec 2016 02:23:12 -0500 Subject: Complete draft of the counters writeup --- .../increment-and-decrement-operations-commute.png | Bin 0 -> 22837 bytes ...ation-based-increment-and-decrement-counter.png | Bin 259325 -> 231349 bytes .../operation-based-increment-only-counter.png | Bin 236423 -> 275467 bytes ...sed-increment-and-decrement-counter-correct.png | Bin 250168 -> 302107 bytes ...ent-and-decrement-counter-incorrect-lattice.png | Bin 0 -> 42949 bytes ...d-increment-and-decrement-counter-incorrect.png | Bin 247402 -> 298653 bytes .../state-based-increment-only-counter-correct.png | Bin 240649 -> 282239 bytes ...tate-based-increment-only-counter-incorrect.png | Bin 241905 -> 283474 bytes 8 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 chapter/6/resources/images/counters/increment-and-decrement-operations-commute.png create mode 100644 chapter/6/resources/images/counters/state-based-increment-and-decrement-counter-incorrect-lattice.png (limited to 'chapter/6/resources') 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 Binary files /dev/null and b/chapter/6/resources/images/counters/increment-and-decrement-operations-commute.png 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 index f046c0b..ddbc789 100644 Binary files a/chapter/6/resources/images/counters/operation-based-increment-and-decrement-counter.png and b/chapter/6/resources/images/counters/operation-based-increment-and-decrement-counter.png 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 index 398c562..1231b92 100644 Binary files a/chapter/6/resources/images/counters/operation-based-increment-only-counter.png and b/chapter/6/resources/images/counters/operation-based-increment-only-counter.png 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 index 0d6468b..880aee0 100644 Binary files a/chapter/6/resources/images/counters/state-based-increment-and-decrement-counter-correct.png and b/chapter/6/resources/images/counters/state-based-increment-and-decrement-counter-correct.png 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 Binary files /dev/null and b/chapter/6/resources/images/counters/state-based-increment-and-decrement-counter-incorrect-lattice.png 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 index 3f7f1b9..7981767 100644 Binary files a/chapter/6/resources/images/counters/state-based-increment-and-decrement-counter-incorrect.png and b/chapter/6/resources/images/counters/state-based-increment-and-decrement-counter-incorrect.png 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 index 4ca2843..c382f8b 100644 Binary files a/chapter/6/resources/images/counters/state-based-increment-only-counter-correct.png and b/chapter/6/resources/images/counters/state-based-increment-only-counter-correct.png 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 index 3f95e59..3e79e42 100644 Binary files a/chapter/6/resources/images/counters/state-based-increment-only-counter-incorrect.png and b/chapter/6/resources/images/counters/state-based-increment-only-counter-incorrect.png differ -- cgit v1.2.3 From 2a9048a1f87a2fcff1d9fcdd035108cec4b44a14 Mon Sep 17 00:00:00 2001 From: Aviral Goel Date: Mon, 19 Dec 2016 14:23:50 -0500 Subject: Added lattice diagram for the state based pn counter --- ...ncrement-and-decrement-counter-correct-lattice.png | Bin 0 -> 1346630 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 chapter/6/resources/images/counters/state-based-increment-and-decrement-counter-correct-lattice.png (limited to 'chapter/6/resources') 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 Binary files /dev/null and b/chapter/6/resources/images/counters/state-based-increment-and-decrement-counter-correct-lattice.png differ -- cgit v1.2.3