diff options
| author | Heather Miller <heather.miller@epfl.ch> | 2017-01-02 16:10:10 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-01-02 16:10:10 +0100 |
| commit | 8428c40f79060169e85bdf740a9432b933a47160 (patch) | |
| tree | 9950fdb91b93a3c37c4de8e03d4e853493b59deb /chapter/6/resources/code/counters/python/operation-based-increment-and-decrement-counter.py | |
| parent | 67118db13c3acb378da9a853d8119e82e20d306a (diff) | |
| parent | f27ba2bd06be195a06fe11b571aebd9a7c1ef930 (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-and-decrement-counter.py')
| -rw-r--r-- | chapter/6/resources/code/counters/python/operation-based-increment-and-decrement-counter.py | 20 |
1 files changed, 20 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) |
