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 --- ...peration-based-increment-and-decrement-counter.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 chapter/6/resources/code/counters/python/operation-based-increment-and-decrement-counter.py (limited to 'chapter/6/resources/code/counters/python/operation-based-increment-and-decrement-counter.py') 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) -- cgit v1.2.3